cpp_friend - 8BitsCoding/RobotMentor GitHub Wiki

friendλŠ” μœ„ν—˜... μ΅œλŒ€ν•œ μ“°μ§€λ§μž

friend μ‚¬μš©

// X.h
class X {
    friend class Y;
private:
    int mPrivateInt;
};
// Y.h
#include "x.h"
class Y {
public:
    void Foo(X& x) {x.mPrivateInt += 10;}
};

μ „μ—­ ν•¨μˆ˜μ—μ„œ friend μ‚¬μš©ν•˜κΈ°

// X.h
class X {
    friend void Foo(X& x);
private:
    int mPrivateInt;
};
// Global
void Foo(X& x)