Yes I know that private
modifier created in order to prohibit access to class data
but isn't friend
intended to allow special access to it?
Compiler:
main.cpp: In member function 'void C::blah(B&)':
main.cpp:48:26: error: 'int B::a' is private within this context
std::cout << obj.a << std::endl;
Everything below is implemented the way as it is in many tutorials.
May be it's just a silly mistake I made and blind to spot.
class C;
class B {
private:
int a = 2;
public:
friend void blah(B& obj);
};
class C {
public:
void blah(B& obj) {
std::cout << obj.a << std::endl; //*
}
};
*Member B::a is inaccessible