We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
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;
const string& getName() const{ return names; }; const string& getAdds() const{ return adds; }; friend istream& read(istream& is, Person& person); friend ostream& print(const ostream& os, const Person& person);
};
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:
建议:
方便别人查阅&回答&学习.
Sorry, something went wrong.
No branches or pull requests
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: