在这种背景下私人,男人的思想肯定不会扭曲吗? [英] private within this context, the mind of man is surely not this twisted ?
问题描述
a级
{
public:
int x;
private:
int y;
}
b级:公开a
{
public :
void b :: somemethod()
}
void b :: somemethod()
{
y = 20; //< - 编译错误,什么?不,男人的心思肯定是
不是这个扭曲的
}
我期待b拥有一切somemethod
WTF?
class a
{
public:
int x;
private:
int y;
}
class b : public a
{
public:
void b::somemethod()
}
void b::somemethod()
{
y = 20; // <- compiler error, what? no, the mind of man is surely
not this twisted
}
I was expecting b to have everything a has and "somemethod"
WTF ?
推荐答案
Greg写道:
Greg wrote:
class a
{
public:
int x;
private:
int y;
}
class a
{
public:
int x;
private:
int y;
}
;
;
>
b级:公开a
{
公开:
void b :: somemethod ()
>
class b : public a
{
public:
void b::somemethod()
;
;
}
}
;
;
>
void b :: somemethod()
{
y = 20; //< - 编译错误,什么?不,男人的心思肯定是
不是这个扭曲的
>
void b::somemethod()
{
y = 20; // <- compiler error, what? no, the mind of man is surely
not this twisted
嗯? ''''是私人的。它不能被*除了*来自一个成员
的''a''或来自其*朋友*。 ''b''不是会员而不是朋友。
这就是'y''无法访问的原因。
Huh? ''y'' is private. It cannot be accessed *except* from a member
of ''a'' or from its *friend*. ''b'' is not a member and not a friend.
That''s why ''y'' is not accessible.
}
我期待b拥有一切已经拥有的东西和somemethod
WTF?
}
I was expecting b to have everything a has and "somemethod"
WTF ?
再次阅读你最喜欢的C ++书籍,特别是解释
''private''的部分。
>
V
-
请在通过电子邮件回复时删除资金''A'
我不知道回复最热门的回复,请不要问
Read your favorite C++ book again, especially the part where
''private'' is explained.
V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask
Greg写道:
Greg wrote:
class a
{
public:
int x;
private:
int y;
}
b级:公共a
{
$ b $公开:
void b :: somemethod()
}
void b :: somemethod()
{
y = 20; //< - 编译错误,什么?不,男人的心思肯定是
不是这个扭曲的
}
我期待b拥有一切somemethod
WTF?
class a
{
public:
int x;
private:
int y;
}
class b : public a
{
public:
void b::somemethod()
}
void b::somemethod()
{
y = 20; // <- compiler error, what? no, the mind of man is surely
not this twisted
}
I was expecting b to have everything a has and "somemethod"
WTF ?
派生类无法访问基类中的私有成员。
派生类*可以*访问基础中的公共成员和受保护成员。
派生类访问基础中私有成员的唯一方法
是基类声明派生类(或至少是有问题的
成员函数)的朋友。
A derived class cannot access private members in the base class. The
derived class *can* access public and protected members in the base.
The only way for a derived class to access private members in the base
is for the base class to declare the derived class (or at least the
member function in question) a friend.
Bleargh,我的C ++测试仪是8.6,这个设计是cac。那么我如何获得一个可以访问私有成员的
?或者我怎样才能使
具有相同的整体设计并避免这种困境呢?
Bleargh, my C++ hateometer is at 8.6, that design is cac. So how do I
derive a class that can access the private members ? Or how can I make
the same overall design and avoid this dilema ?
这篇关于在这种背景下私人,男人的思想肯定不会扭曲吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!