如何使我的班级朋友成为班上的朋友?
问题描述:
我认为这是可能的,但是编译器抱怨它无法访问我班上受保护的/私人的成员.我曾尝试过移动和更改签名,但是找不到有效的组合.
I'm thinking this is possible, but the compiler is complaining it cannot access the protected/private members of my class. I've tried moving stuff around and changing signatures, but can't find a combination that works.
我基本上有:
class MyClass
{
public:
friend int main(int argc, char** argv);
private:
void test()
{
cout << "My friend has accessed my member" << endl;
}
};
int main(int argc, char** argv)
{
MyClass mc;
mc.test();
}