public: foo():m_bar(* this){} }; 另一个选项是放弃这个过时的编译器。 V - 请删除大写''A'的当通过电子邮件回复 我没有回复最热门的回复,请不要问Declare classs bar as a friend of foo:class foo{class bar; // forward-declaration of a memberfriend class bar;class bar{friend class foo;// ^^^^^^^^^^^^^^^^// do you really need this here?foo & m_f;public:bar(foo & f) : m_f(f) {}void wii(){m_f.poo(); // #error C2248}} m_bar;void poo() {}public:foo() : m_bar(*this) {}};The other option is to abandon this outdated compiler for good.V--Please remove capital ''A''s when replying by e-mailI do not respond to top-posted replies, please don''t ask Gernot Frisch写道:Gernot Frisch wrote:此代码适用于VC7.1。但VC6拒绝编译。 class foo {班级酒吧 {朋友班foo; foo& m_f; public: bar(foo& f):m_f(f){} void wii() { m_f.poo(); // #error C2248 } } m_bar; void poo(){} 公开: foo():m_bar (* this){} }; 错误C2248:''poo'':无法访问类中声明的私有成员''foo''什么我可以吗? This code works on VC7.1. But VC6 refuses to compile. class foo { class bar { friend class foo; foo & m_f; public: bar(foo & f) : m_f(f) {} void wii() { m_f.poo(); // #error C2248 } } m_bar; void poo() {} public: foo() : m_bar(*this) {} }; error C2248: ''poo'' : cannot access private member declared in class ''foo'' What can I doo? 你可以做任何其他类访问该成员:将 成员公开或制作栏foo的朋友。The same you can do to make any other class access that member: Make themember public or make bar a friend of foo. 这篇关于无法访问父类私有成员(VC6)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-21 08:18