J
Jaspreet
I am working on a code which is similar to the following snippet:
#include <iostream>
using namespace std;
class def;
class abc
{
friend class def;
private:
int p;
};
class def
{
public:
void gg()
{
abc a1;
a1.p = 20;
}
};
int main()
{
def d1;
}
I apologise for the cryptic names of the classes. My doubt is how can I
access the private member p of class abc in gg() method of def class.
Friend class can access the private data of the other class but here I
am trying to acess the private data using an object. Is that valid ?
The code compiles fine on VC 6.0. I know VC6.0 is not a compiler one
should be using if he needs to learn C++ but since I am working on
mobile applications, I have to use VC6.0.
Is this a case of a broken compiler ? I do not think so because the
code also compiles fine on Metrowerks Codewarrior which is based on
gcc.
Please let me know.
#include <iostream>
using namespace std;
class def;
class abc
{
friend class def;
private:
int p;
};
class def
{
public:
void gg()
{
abc a1;
a1.p = 20;
}
};
int main()
{
def d1;
}
I apologise for the cryptic names of the classes. My doubt is how can I
access the private member p of class abc in gg() method of def class.
Friend class can access the private data of the other class but here I
am trying to acess the private data using an object. Is that valid ?
The code compiles fine on VC 6.0. I know VC6.0 is not a compiler one
should be using if he needs to learn C++ but since I am working on
mobile applications, I have to use VC6.0.
Is this a case of a broken compiler ? I do not think so because the
code also compiles fine on Metrowerks Codewarrior which is based on
gcc.
Please let me know.