写新类时 undefined reference to
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++
求助
相关推荐
undefined reference to 'pthread_create'的解决方法
undefined reference to 'pthread_create'的解决方法,需要的朋友可以参考一下
undefined reference to ‘pthread_create’的解决方法
照着GUN/Linux编程指南中的一个例子输入编译,结果出现如下错误: undefined reference to ‘pthread_create’undefined reference to ‘pthread_join’ 问题原因: pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库。 问题解决: 在编译中要加 -lpthread参数 gcc thread.c -o thread -lpthr
【转】undefined reference to错误的解决方法.doc
【转】undefined reference to错误的解决方法.doc
undefined reference to `SetPduPowerConsumptionCnt'错误的解决方法
编译时出现undefined reference to `SetPduPowerConsumptionCnt'错误要如何解决呢?有没有什么好的解决方法?下面小编就为大家解答吧,如果你也遇到了这种情况,可以过来参考下
C生成静态库给C++调用出现undefined reference to ...解决方案_cpp
C生成静态库给C++调用出现undefined reference to ...解决方案 已经写好makefile,还有头文件,看注释,基本没问题的



