| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 449 人关注过本帖
标题:[求助]看下问题出在哪?
只看楼主 加入收藏
a8451727
Rank: 1
等 级:新手上路
帖 子:238
专家分:5
注 册:2007-5-22
结帖率:86.67%
收藏
 问题点数:0 回复次数:3 
[求助]看下问题出在哪?

这个是一个名字的类。帮我看下哪错了?

类文件:

#include <iostream>
#include <string>
#include <cassert>
using namespace std;

class Name
{
public:
Name();
Name (string first,string middle,string last);
string getFirstName() const;
string getLastName() const;
string getMiddleName() const;
string getsignature() const;

void print(ostream& out) const;

private:
string myFirstName,
myMiddleName,
myLastName;
};

inline string Name::getFirstName() const
{
return myFirstName;
}
inline string Name::getLastName() const
{
return myLastName;
}
inline string Name::getMiddleName() const
{
assert (myMiddleName.size()>0);
return myMiddleName;
}

inline string Name::getsignature() const
{
return getFirstName()+' '
+getMiddleName()+"."
+getLastName();
}

inline void Name::print(ostream& out) const
{
cout <<getFirstName()+' '
+getMiddleName()+' '
+getLastName();
}

/**********************/
驱动程序:

#include <iostream>
#include "Name.h"
using namespace std;

int main()
{
Name hisName("Hohn","Paul","Jones"),
herName("Mary","Anne","Smith");

cout <<hisName.getsignature()<<"\n\n";

herName.print(cout);

return 0;
}

/******************/
错误信息:
error LNK2001: unresolved external symbol "public: __thiscall Name::Name(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::alloc
ator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Name@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@00@Z)
Debug/书本208.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.



搜索更多相关主题的帖子: private include public middle 
2007-05-23 16:07
yushui
Rank: 3Rank: 3
等 级:论坛游民
威 望:7
帖 子:1355
专家分:22
注 册:2006-7-19
收藏
得分:0 


#include <iostream>
#include <string>
#include <cassert>
using namespace std;

class Name
{
public:
Name();
Name (string first,string middle,string last);
string getFirstName() const;
string getLastName() const;
string getMiddleName() const;
string getsignature() const;

void print(ostream& out) const;

private:
string myFirstName,
myMiddleName,
myLastName;
};
Name::Name(string first,string middle,string last)//你忘了构造函数了
{
myFirstName=first;
myMiddleName= middle;
myLastName= last ;
}

inline string Name::getFirstName() const
{
return myFirstName;
}
inline string Name::getLastName() const
{
return myLastName;
}
inline string Name::getMiddleName() const
{
assert (myMiddleName.size()>0);
return myMiddleName;
}

inline string Name::getsignature() const
{
return getFirstName()+' '
+getMiddleName()+"."
+getLastName();
}

inline void Name::print(ostream& out) const
{
cout <<getFirstName()+' '
+getMiddleName()+' '
+getLastName();
}

/**********************/
//驱动程序:

#include <iostream>
//#include "Name.h"
using namespace std;

int main()
{
Name hisName("Hohn","Paul","Jones"),herName("Mary","Anne","Smith");

cout <<hisName.getsignature()<<"\n\n";

herName.print(cout);

return 0;
}


fighting!from now on!
2007-05-23 16:56
a8451727
Rank: 1
等 级:新手上路
帖 子:238
专家分:5
注 册:2007-5-22
收藏
得分:0 

非常感谢,感动中


2007-05-23 18:24
raulxxyuer
Rank: 1
等 级:新手上路
威 望:1
帖 子:178
专家分:0
注 册:2007-4-23
收藏
得分:0 

我很沒用,總是學不會遺忘,總是學不會割捨本不屬於我的東西。
2007-05-23 20:16
快速回复:[求助]看下问题出在哪?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032926 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved