本文介绍了访问内部类的私有成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

A级

{

公开:

B级;

int funct(const B& b);

};


A类:: B

{

私人:

int _member;

};


int A :: funct(const A :: B& b)

{

返回10 * b._member; //不会编译

}


////////////////////// //////

以上代码无法编译,因为我收到错误的结果

成员_member无法从A :: funct访问(const A :: B&)


除此之外,还有公布的会员资格吗?


谢谢,


~S

Class A
{
public:
class B;
int funct(const B &b);
};

Class A::B
{
private:
int _member;
};

int A::funct(const A::B &b)
{
return 10*b._member; //won''t compile
}

////////////////////////////
The above code will not compile, as I get a error to the effect of
member _member not accessable from A::funct(const A::B&)

Is there anyway around this, short of declaring _member to be public?

Thanks,

~S

推荐答案





制作A a B.的朋友


A级:: B

{

朋友A级;

...


john



Make A a friend of B.

class A::B
{
friend class A;
...

john



这篇关于访问内部类的私有成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 08:02
查看更多