数据隐藏? [英] Data hiding?

查看:68
本文介绍了数据隐藏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的前提是我不太了解C ++,但是...我想知道这个数据是什么隐藏

的东西...我的意思是,如果我能看看标题(我需要它是因为

类),那么隐藏了什么?


有人可以给我一个隐藏用户的例子吗?



解决方案

Lorenzo Villari写道:

我的前提我不知道C ++很好但是......我想知道这个数据隐藏了什么东西......我的意思是,如果我可以看一下标题(我需要它继续使用
类),那么''隐藏了什么?

有人可以给我一个隐藏用户的例子吗?



也许隐藏不是这里最好的术语。 />

私有类成员的想法是*使用*对象的代码从一个类实例化的
无法直接访问它们。这意味着

该类的实现可以更改而无需更改

客户端代码。


HTH,
- g


-

Artie Gold - 德克萨斯州奥斯汀

哦,为了好的常规旧垃圾邮件的旧时代。


>也许隐藏不是这里最好的术语。


私有类成员的想法是*使用从类中实例化的*对象的代码无法访问它们(直)。这意味着该类的实现可以在不需要更改客户端代码的情况下进行更改。



所以这意味着我可以看到它但不能使用它?这有用吗?

哦...也许你的意思是这些功能只能用于特定的类?

这就像声明静态函数一样?


但是等一下......


让我们试一试。


class myclass {

private:

int x;

mytype y;

public:

myclass(...);

};


注意变量''y'',它是私有的和用户的班级不能使用它所以我们

说它是隐藏的或封装,但等待......他们仍然需要

来定义它。如果''mytype''的定义需要一大堆包含在一堆包含文件中的特殊内容,那么用户就会被所有这些定义所困扰。在他的名字空间。然后,如果其中一个文件发生了变化,那么用户代码就不会被改变,但是它会被重新编译。

。 br />

对我而言,这是C ++最大的缺陷。我知道有各种各样的工作

左右但是这会使事情变得更加复杂和混乱。有趣的是,Lorenzo不太熟悉C ++马上就拿起来了。


佩里。

" Artie Gold" < AR ******* @ austin.rr.com>在消息中写道

新闻:3F ************** @ austin.rr.com ...

Lorenzo Villari写道:< blockquote class =post_quotes>我的前提我不太了解C ++但是...我想知道这个数据是什么
隐藏的东西......我的意思是,如果我能看看标题(我需要它是因为
这个类),那么隐藏了什么?

有人可以给我一个隐藏用户的例子吗?


也许`隐藏''不是这里最好的术语。

私有类成员的想法是*使用从类中实例化的*对象的代码无法直接访问它们。这意味着该类的实现可以更改而无需更改客户端代码。

HTH,
--ag

-
Artie Gold - 德克萨斯州奥斯汀
哦,对于常规老垃圾邮件的美好时光。



I premise I don''t know C++ well but... I wondered what is this data hiding
thing... I mean, if I can look at the header (and i need it beacuse of the
class), then what''s hidden?

Can someone give me an example of something hidden from the user?



解决方案

Lorenzo Villari wrote:

I premise I don''t know C++ well but... I wondered what is this data hiding
thing... I mean, if I can look at the header (and i need it beacuse of the
class), then what''s hidden?

Can someone give me an example of something hidden from the user?


Perhaps `hiding'' is not the best term here.

The idea of private class members is that code that *uses* objects
instantiated from a class cannot access them (directly). This means
that the class'' implementation can change without needing to change
client code.

HTH,
--ag

--
Artie Gold -- Austin, Texas
Oh, for the good old days of regular old SPAM.


> Perhaps `hiding'' is not the best term here.


The idea of private class members is that code that *uses* objects
instantiated from a class cannot access them (directly). This means
that the class'' implementation can change without needing to change
client code.


So this means I can see it but cannot use it? How useful is this?
Oh... maybe you meant those function can be used only by a particular class?
Is this like declaring static a function?


But wait a minute...

Lets try an example.

class myclass {
private:
int x;
mytype y;
public:
myclass(...);
};

Notice variable ''y'', it''s private and users of the class can''t use it so we
say it is "hidden" or "encapsulated", but wait ... they will still have to
define it. What if the definition of ''mytype'' requires a whole bunch of
special stuff located in a bunch of include files, the user is stuck to have
all those definitions in his name space. Then, what if there is a change in
one of those files, the user code won''t have to be changed but it will have
to be recompiled.

To me this is C++ ''s greatest flaw. I know there are all sorts of work
arounds but that makes things more complicated and messy. Interesting that
Lorenzo who "don''t know C++ well " picked up on it right away.

Perry.
"Artie Gold" <ar*******@austin.rr.com> wrote in message
news:3F**************@austin.rr.com...

Lorenzo Villari wrote:

I premise I don''t know C++ well but... I wondered what is this data hiding thing... I mean, if I can look at the header (and i need it beacuse of the class), then what''s hidden?

Can someone give me an example of something hidden from the user?


Perhaps `hiding'' is not the best term here.

The idea of private class members is that code that *uses* objects
instantiated from a class cannot access them (directly). This means
that the class'' implementation can change without needing to change
client code.

HTH,
--ag

--
Artie Gold -- Austin, Texas
Oh, for the good old days of regular old SPAM.



这篇关于数据隐藏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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