无法解析的外部符号
看小甲鱼的c++视频,第20,友元部分;自己在vs2012上写demo;运行后输出ConsoleApplication10.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall Others::Others(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Others@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z),该符号在函数 _main 中被引用
1>d:\我的资料库\documents\visual studio 2012\Projects\ConsoleApplication10\Debug\ConsoleApplication10.exe : fatal error LNK1120: 1 个无法解析的外部命令
demo代码如下 : 求大家指导;
// ConsoleApplication10.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <string>
#include <iostream>
class Lover {
public :
Lover(std::string theName);
void kiss(Lover *lover);
protected:
std::string name;
friend class Others;
};
class Boy :public Lover {
public :
Boy(std::string theName);
};
class Girl:public Lover {
public :
Girl(std::string theName);
};
class Others {
public :
Others(std::string theName);
void kiss(Lover *lover);
protected:
std::string name;
};
void Others::kiss(Lover *lover){
std::cout <<name<<"kisss=============="<<lover->name<<std::endl;
}
Lover::Lover(std::string theName){
name =theName;
}
void Lover::kiss(Lover *lover){
std::cout <<name <<"kiss ---"<<lover->name<<std::endl;
}
Boy::Boy(std::string theName):Lover(theName){
}
Girl::Girl(std::string theName):Lover(theName){}
int main(int argc, _TCHAR* argv[])
{
Boy boy ("aaa");
Girl g("bbbbb");
Others o("cccc");
g.kiss(&boy);
o.kiss(&g);
system("pause");
return 0;
}
你没有实现Others的构造函数啊~~:ton:Others::Others(std::string theName)
{
name = theName;
} nsonline 发表于 2014-4-23 08:53 static/image/common/back.gif
你没有实现Others的构造函数啊~~
非常感谢,已经解决!
页:
[1]