如何使我的班级朋友成为班上的朋友? [英] How do I make main a friend of my class?
本文介绍了如何使我的班级朋友成为班上的朋友?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我认为这是可能的,但是编译器抱怨它无法访问我班上受保护的/私人的成员.我曾尝试过移动和更改签名,但是找不到有效的组合.
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();
}
推荐答案
您所拥有的是正确的.
这篇关于如何使我的班级朋友成为班上的朋友?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文