写新类时 undefined reference to
我实现stack这个类的时候,然后简单调用测试push函数,出现如下错误
main.o(.text+0xf0): undefined reference to `stack::push(basic_string<char, string_char_traits<char>, __default_alloc_template<false, 0> > &)'
collect2: ld returned 1 exit status
代码如下
stack.h
1 #include <string>
2 #include <vector>
3
4 using namespace std;
5
6 class stack{
7 public:
10 bool push(string& str);
11 // string pop();
12 // string find(int pos);
13 // int size(){return str_vec.size();}
15
16 private:
17 vector<string> str_vec;
18 };
stack.cc
1 #incldue "stack.h"
2
3 string str;
4
14
15 bool stack::push(string& str){
16 str_vec.push_back(str);
17 return true;
18 }
19 /*
20 string stack::pop(){
21 return str_vec.pop_back();
22 }
23
24 string stack::find(int pos){
25 return str_vec[pos];
26 }*/
main.cc
1 #include "stack.h"
2 #include <fstream>
3 #include <iostream>
4
5 int main(){
6 stack _st;
7 string word;
8 ifstream ifile("./article.txt");
9 if(!ifile)
10 cerr<<"file error"<<endl;
11
12 cout<<"pls input"<<endl;
13 //while(cin>>word){
14 while(ifile>>word){
15 if( !_st.push(word))
16 cout<<"push error"<<endl;
17 }
28 }
freebsd g++
求助