J
Jade Fox
Can anyone tell me what's wrong with the following C++ program?
It compiles ok with GCC and SUN CC, but Visual C++ insists the
overloaded operator<< cannot access a private member?
And yet the same function with a different operator symbol is fine.
Is this a VC bug?
C:\p.cpp(14) : error C2248: 'm' : cannot access private member declared in class 'P'
C:\tchen\lab6.cpp(9) : see declaration of 'm'
---
#include <iostream>
using namespace std;
class P
{
friend ostream & operator-=(ostream& out, const P& p);
friend ostream & operator<<(ostream& out, const P& p);
private:
int m;
};
ostream & operator<<(ostream& out, const P& p)
{
int k = p.m;
return out;
}
ostream & operator-=(ostream& out, const P& p)
{
int k = p.m;
return out;
}
int main()
{
return 0;
}
It compiles ok with GCC and SUN CC, but Visual C++ insists the
overloaded operator<< cannot access a private member?
And yet the same function with a different operator symbol is fine.
Is this a VC bug?
C:\p.cpp(14) : error C2248: 'm' : cannot access private member declared in class 'P'
C:\tchen\lab6.cpp(9) : see declaration of 'm'
---
#include <iostream>
using namespace std;
class P
{
friend ostream & operator-=(ostream& out, const P& p);
friend ostream & operator<<(ostream& out, const P& p);
private:
int m;
};
ostream & operator<<(ostream& out, const P& p)
{
int k = p.m;
return out;
}
ostream & operator-=(ostream& out, const P& p)
{
int k = p.m;
return out;
}
int main()
{
return 0;
}