为什么在C ++中使用class关键字 [英] why class keyword in C++

查看:151
本文介绍了为什么在C ++中使用class关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




如果struct关键字支持class关键字的所有功能,

只有我发现的差异是成员的可访问性不同

struct是公共的,类是私有的。

这个可访问性功能用户可以使用Accessor public,

private或protected。

那么为什么class关键字是用C ++实现的。


提前谢谢。

解决方案

< blockquote> Viru Rathore写道:

如果struct关键字支持class关键字的所有功能,
只有我发现的不同之处是成员的可访问性不同
在struct中是公共的class有私有。
这个可访问性功能用户可以使用Accessor public,
private或protected。

为什么class关键字是用C ++实现的。




因为那样凉爽。


V

-

请通过邮件回复从我的地址删除资金


Viru Rathore写道:


如果struct关键字支持class关键字的所有功能,
只有我发现的不同之处是成员的可访问性不同
struct是public而class是private。
这个可访问性功能用户可以使用Accessor public,<私有或受保护。

为什么class关键字是用C ++实现的。

提前致谢。



重点OOD / OOP是通过创建黑色

框来隐藏信息和进程,只有公开的接口,(需要知道

基础可用的东西)。因此,对于OOD / OOP开发的对象

,大多数数据和方法通常都是私有的。但是为了落后

与旧的C代码结构的兼容性必须得到数据支持和

方法默认为公开。就个人而言,我总是在一个对象中包含明确的范围声明(私人,受保护或公开)。


JB


n2xssvv g02gfr12930写道:

Viru Rathore写道:


如果struct关键字支持class关键字的所有功能,
只有差异我发现成员的可访问性不同
结构是公共的,而且类是私有的。
这个可访问性功能用户可以通过使用Accessor public,
private或者保护。

为什么class关键字是用C ++实现的。

提前感谢。


OOD / OOP的重点是信息和进程隐藏通过创建只有公共接口的黑色
框,(需要知道可用的基础)。因此,对于OOD / OOP开发的对象大多数数据和方法通常都是私有的。




然而,我觉得放置它更合乎逻辑首先是公众成员,因为他们是最大的一群人感兴趣的部分。所以

我的课程总是如下:


class Foo

{

public:


它与继承类似。默认是私有的,即使一个

通常更公开地以公共方式继承。




If struct keyword is support the all functionallity of class keyword,
only differance i have found is accessibility of member is different in
struct is public and class has private.
This accessbility feature user can got by using Accessor public,
private or protected.
So why class keyword is implemented in C++.

Thanks in advance.

解决方案

Viru Rathore wrote:

If struct keyword is support the all functionallity of class keyword,
only differance i have found is accessibility of member is different
in struct is public and class has private.
This accessbility feature user can got by using Accessor public,
private or protected.
So why class keyword is implemented in C++.



Because it''s cooler that way.

V
--
Please remove capital As from my address when replying by mail


Viru Rathore wrote:


If struct keyword is support the all functionallity of class keyword,
only differance i have found is accessibility of member is different in
struct is public and class has private.
This accessbility feature user can got by using Accessor public,
private or protected.
So why class keyword is implemented in C++.

Thanks in advance.


The point of OOD/OOP is information and process hiding by creating black
boxes with only the interfaces publicly available, (the need to know
basis for what is available). Hence for OOD/OOP development of an object
most of the data and methods would normally be private. But for backward
compatibility with old C code struct had to be supported with data and
methods defaulting to being public. Personally I always include explicit
declaration of scope, (private,protected or public), within an object.

JB


n2xssvv g02gfr12930 wrote:

Viru Rathore wrote:


If struct keyword is support the all functionallity of class keyword,
only differance i have found is accessibility of member is different in
struct is public and class has private.
This accessbility feature user can got by using Accessor public,
private or protected.
So why class keyword is implemented in C++.

Thanks in advance.


The point of OOD/OOP is information and process hiding by creating black
boxes with only the interfaces publicly available, (the need to know
basis for what is available). Hence for OOD/OOP development of an object
most of the data and methods would normally be private.



However, I find it much more logical to put the public members first, since
they are the part that is interesting for the largest group of people. So
my classes always start like:

class Foo
{
public:

It''s similar with inheritance. The default is private, even though one
usually inherits publically way more often.


这篇关于为什么在C ++中使用class关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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