且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

c ++运算符是不明确的和其他

更新时间:2023-11-10 09:06:16

The problem is that obj.getEmployAt(i); returns a rvalue temporary CStudentEmploy object which you send to your operator<< overlaod. But the operator overload expects a reference and can not bind to an rvalue.

You will have to take a const reference instead

ostream& operator<<(ostream& os, const CStudentEmploy &obj) {
                                 ^^^^^

and fix the functions used in it as const for example

string GetName() const { return m_strName; }
                 ^^^^^



Or you can fix your getEmployAt function to return a reference instead.

CStudentEmploy& getEmployAt(int i) { return m_vData[i]; }
             ^^^



As mentioned in the comments: I don't know what compiler you are using but void is not a valid return value for main. use int main and return 0;

相关阅读

推荐文章