请帮我解释为什么我在提到评论家时发生错误。我真的被困在这里! 我应该给出哪些其他细节?为什么我得到这个错误:在C++中'operator <<'不匹配?
Main.cpp的
#include <iostream>
#include<person.h>
#include <sstream>
int main()
{
cout << "Constructor Overloading Demo !!!" << endl;
person vish;
cout << vish.toString() << endl; /* I get an error for this statement though I feel this is correct */
return 0;
}
person.cpp //构造函数定义文件
#include "person.h"
#include <sstream>
person::person()
{
name = "vish";
age = 25;
//ctor
}
void person::toString()
{
stringstream st;
st << "Name: ";
st << name;
st << "& Age: ";
st << age;
prnt = st.str();
cout << prnt << endl;
//return 10;
}
person.h //构造函数声明
#ifndef PERSON_H
#define PERSON_H
#include<iostream>
using namespace std;
class person
{
public:
person();
void toString();
//virtual ~person();
protected:
private:
string name;
int age;
string prnt;
};
#endif // PERSON_H
偏题:如果你真的要使用'命名空间标准;'**确定不要把它放在标题**中。 –
那么,开始'人:: toString'是类型'无效',我不认为iostream的'<<'有'无效'的重载 – infixed
@infixed是否有可能有这样的过载? – Slava