C
Cotangent Alpha
When class A is declared before class B is defined, I am unable to
make B::baz() a friend function of class A. I get this error: member
'void B::baz()' declared as friend before type 'B' defined. Is it
possible to resolve this?
Here is the code:
class B;
class A
{
public:
void foo() {
cout << "A::foo()" << endl;
}
private:
// This function should be accessible to B only and nothing else.
void bar() {
cout << "A::bar()" << endl;
}
friend void B::baz();
};
class B
{
public:
void baz() {
A a;
a.bar();
}
};
int main()
{
B b = b;
b.baz();
}
make B::baz() a friend function of class A. I get this error: member
'void B::baz()' declared as friend before type 'B' defined. Is it
possible to resolve this?
Here is the code:
class B;
class A
{
public:
void foo() {
cout << "A::foo()" << endl;
}
private:
// This function should be accessible to B only and nothing else.
void bar() {
cout << "A::bar()" << endl;
}
friend void B::baz();
};
class B
{
public:
void baz() {
A a;
a.bar();
}
};
int main()
{
B b = b;
b.baz();
}