I've noticed what I think is a bug in VC++ 6.0. Can someone confirm and
also test whether it is still present in later versions?
In C++, as in C, it's legal to use the same name for both a user-defined
type and a function or object. When the type name is referenced, if it
is, it must be preceded by the keyword for its declaration.
It is also legal to forward-declare a class name in a friend statement,
making an as-yet-undefined class a friend of the current class.
The following code should be legal but instead VC++ 6.0 produces an
error message.
class A {
private:
int x;
void a(); // declares member function
friend class a; // forward declares a as a class and friend
};
class a{
public:
a(A &aa) {++aa.x} // reference to private member should be allowed
// because a is a friend of A
};
The error occurs in the constructor of class a with the message "'x' :
cannot access private member declared in class 'A'".
If I move the friend statement above the declaration of function a(), or
if I forward declare class a before class A the code compiles without error.
Norm
--
--
To reply, change domain to an adult feline.