Visual C++ bug?

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;
}
 
L

Leor Zolman

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'

Yes, this is a VC6 bug. Apply Service pack 6:

http://msdn.microsoft.com/vstudio/downloads/updates/sp/vs6/sp6/default.aspx

-leor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,169
Messages
2,570,917
Members
47,458
Latest member
Chris#

Latest Threads

Top