一个小错误

visual4825 2004-10-27 07:59:44
mutiple_return_value_reference.obj : error LNK2001: unresolved external symbol "class SimpleCat * __cdecl Function2(class SimpleCat *)" (?Function2@@YAPAVSimpleCat@@PAV1@@Z)
...全文
90 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
newegg2002 2004-10-27
  • 打赏
  • 举报
回复
大意了,楼主:
SimpleCat *Function(SimpleCat *the_cat)
这一句按你的意思应该是:
SimpleCat *Function2(SimpleCat *the_cat)的.
因为你声明了Function2.在主函数中调用了它.但是却没有定义它.所以编译器会报错:
[Linker error] undefined reference to `Function2(SimpleCat*)'
ttfy1234 2004-10-27
  • 打赏
  • 举报
回复
最后一段,SimpleCat *Function(SimpleCat *the_cat)///////////////////////Function 少写了个2
{
cout << "Function2.return.....\n";
return the_cat;
}


应该是:
SimpleCat *Function2(SimpleCat *the_cat)
{
cout << "Function2.return.....\n";
return the_cat;
}

visual4825 2004-10-27
  • 打赏
  • 举报
回复
下面是我的代码,感觉没什么问题啊???
//Passing objects by reference
//1.00 2004.10.26--------2009.6.5

#include <iostream.h>

class SimpleCat
{
public:
SimpleCat(); //constructor
SimpleCat(SimpleCat&); //copy constructor
~SimpleCat(); //destructor
};

SimpleCat::SimpleCat()
{
cout << "constructor...\n" ;
}

SimpleCat::SimpleCat(SimpleCat&)
{
cout << "copy constructor...\n";
}

SimpleCat::~SimpleCat()
{
cout << "destructor...\n";
}

SimpleCat Function1(SimpleCat the_cat);
SimpleCat* Function2(SimpleCat *the_cat);

int main()
{
cout << "Making a cat...\n";
SimpleCat Frisky;
cout << "Calling Function1...\n";
Function1(Frisky);
cout << "Calling Functionn2...\n";
Function2(&Frisky);

return 0;
}

//Function1, passes by value
SimpleCat Function1(SimpleCat the_cat)
{
cout << "Function1.return*********\n";
return the_cat;
}

SimpleCat *Function(SimpleCat *the_cat)
{
cout << "Function2.return.....\n";
return the_cat;
}
ivorstar 2004-10-27
  • 打赏
  • 举报
回复
编译器说你没有定义过class SimpleCat 这个东东,如果你的程序在引用class SimpleCat 时还没有定义它,可以参考http://community.csdn.net/Expert/topic/3477/3477382.xml?temp=.9230158
goodluckyxl 2004-10-27
  • 打赏
  • 举报
回复
看看你函数体定义了没有

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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