Connecting Tech Pros Worldwide Forums | Help | Site Map

Visual C++ bug?

Jade Fox
Guest
 
Posts: n/a
#1: Jul 22 '05
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;
}

Leor Zolman
Guest
 
Posts: n/a
#2: Jul 22 '05

re: Visual C++ bug?


On 5 May 2004 06:07:46 -0700, cjchen@eden.rutgers.edu (Jade Fox) wrote:
[color=blue]
>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'
>[/color]

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

http://msdn.microsoft.com/vstudio/do...6/default.aspx

-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Closed Thread