c++问题一?
1。我已经定义为友元,为什么还不能访问私有成员?
2。这个错误F:\C++\lab2.cpp(34) : error C2593: 'operator < < ' is ambiguous
#include <iostream>
#include <string>
using namespace std;
class PhoneNumber
{
public :
friend ostream & operator < < ( ostream & output , PhoneNumber & t);
friend istream & operator > > ( istream & input, PhoneNumber & t);
private :
int number;
};
ostream & operator < <( ostream & output , PhoneNumber & t)
{
output < <t.number;
output < <endl;
return output;
}
istream & operator > > ( istream & input, PhoneNumber & t)
{
input> > t.number;
return input;
}
int main()
{
PhoneNumber phone;
cout < < "Enter phone number in the form (0316) 2223517 " < <endl;
cin> > phone;
cout < < "The phone number entered was: ";
cout < <phone;
cout < <endl;
return 0;
}
[解决办法]
把 using namespace std;
换成:
using std::ostream;
using std::istream;
using std::cout;
using std::cin;
using std::endl;
这样在VC6.0上就可以编译通过了, 也可以下载VC6.0的补丁包.
建议不要再用VC6.0 了.
[解决办法]
devcpp上都可以通过的,
VC6要下一个补丁才能通过
[解决办法]
把VC6的SP6打了
PS; f*ck VVc6