帮忙看个问题 undefined reference to `addstring::test(int, int)' collect2: ld returned 1 exit status

zouqingqiu 2009-03-11 04:08:11
file : addstring.h

#include<sstream>
#include<string>
using namespace::std;
class addstring
{
public:

int i ;
ostringstream jason;
string m_string;
string tostring(ostringstream& jason, int na);
int test(int a,int b);
};
file :addstring.cpp

#include<sstream>
#include"addstring.h"

void addstring::addstring()
{
jason.str("");
cout<<"ddd"<<endl;


string m_string = NULL;
}
int addstring::test(int a,int b){
cout<<"test"<<endl;
}

file main.cpp



#include<iostream>
#include<sstream>
#include"addstring.h"
#include<string.h>
using namespace::std;
int main ()
{
addstring add;
add.test(1,2);
}
请大家帮忙看看问题 thks!!!

error main.cpp:(.text+0x1c0): undefined reference to `addstring::test(int, int)'
collect2: ld returned 1 exit status


...全文
509 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoming880828 2011-12-22
  • 打赏
  • 举报
回复
最可能的原因就是1楼了
yangkunhenry 2009-03-11
  • 打赏
  • 举报
回复
再补充下string m_string = NULL; //这样是不对的
按你的意思应该这样 string m_string("");
arong1234 2009-03-11
  • 打赏
  • 举报
回复
你类声明了以下两个函数
string tostring(ostringstream& jason, int na);
int test(int a,int b);
而第一个函数你还没实现
至于你那个构造函数,如3楼,你还写错了,不仅写错了,还没有在类中声明
yangkunhenry 2009-03-11
  • 打赏
  • 举报
回复
file :addstring.cpp
void addstring::addstring()
自定义的构造函数没有声明,而且构造函数是没有返回类型的
topwork 2009-03-11
  • 打赏
  • 举报
回复
把addstring::test加上返回值看看。
arong1234 2009-03-11
  • 打赏
  • 举报
回复
没有把addstring.cpp 也加入编译?

64,676

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧