-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
《C++ Primer》 7.1-7.2部分 #71
Comments
建议:
方便别人查阅&回答&学习. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Person.h:
#include
#include
using namespace::std;
class Person{
public:
Person() = default;
Person(const string &s, const string &r) :
names(s), adds(r){
}
Person(istream& is){
read(is, *this);
}
string names;
string adds;
};
istream& read(istream &is, Person& person){
is >> person.names >> person.adds;
if (!is)
person = Person(); //奇怪的if
return is;
}
ostream& print(ostream &os, const Person& person){
os << person.names << " " << person.adds << endl;
return os;
}
test:
#include "Person.h"
int main(){
Person mine;
print(cout, mine) << endl;
system("pause");
return 0;
}
error LNK2005: "class std::basic_ostream<char,struct std::char_traits > & __cdecl print(class std::basic_ostream<char,struct std::char_traits > &,class Person const &)" (?print@@yaaav?$basic_ostream@DU?$char_traits@D@std@@@std@@aav12@ABVPerson@@@z) 已经在 Person.obj 中定义 D:\C++Test\Project7\Project7\test.obj Project7
error LNK2005: "class std::basic_istream<char,struct std::char_traits > & __cdecl read(class std::basic_istream<char,struct std::char_traits > &,class Person &)" (?read@@yaaav?$basic_istream@DU?$char_traits@D@std@@@std@@aav12@AAVPerson@@@z) 已经在 Person.obj 中定义 D:\C++Test\Project7\Project7\test.obj Project7
error LNK1169: 找到一个或多个多重定义的符号 D:\C++Test\Project7\Debug\Project7.exe Project7
The text was updated successfully, but these errors were encountered: