访问内部类的私有成员 [英] access to private members of internal class

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

问题描述

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

推荐答案



" Shea Martin" < SM ***** @ arcis.com>在消息中写道

news:Yljdc.4779

"Shea Martin" <sm*****@arcis.com> wrote in message
news:Yljdc.4779


G3.43042@localhost ...
G3.43042@localhost...
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&)

无论如何除此之外,还没有宣布_member公开吗?

谢谢,

~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




" Shea Martin" < SM ***** @ arcis.com>在消息中写道

新闻:Yljdc.4779

"Shea Martin" <sm*****@arcis.com> wrote in message
news:Yljdc.4779


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆