为什么我们使用类而不是结构? [英] Why we use classes instead of structure ?

查看:98
本文介绍了为什么我们使用类而不是结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题在我脑海中浮现,因为当我在OOP上工作并使用课程时,我看到我们使用关键字class在我们的程序中创建一个类

但我的问题是,如果我们写'struct'而不是'class'并且我们没有更改,那么即使我们使用构造函数,析构函数,访问说明符等编程没有显示错误,程序仍可以工作

>
为什么我们使用类和创建对象???



我尝试过:



我也想知道为什么我们使用OOP而不是结构化编程,这太简单了,无法编写和理解,我们不需要额外的工作来制作类和其他的

This question arrives in my mind because when i work on OOP and use the classes then i see that we use the keyword 'class' for making a class in our program
But my question is,if we write 'struct' instead of 'class' and no more change we do then the program works
even if we use constructor,destructor,access specifiers etc the compiler did not show an error
So why we use classes and create objects ???

What I have tried:

And also i want to know that why we use OOP instead of structured programming which is too simple to write and understand and we don't need to work extra on making classes and others

推荐答案

在C ++类和结构体中或多或少相同。请参阅我给你的上一个链接以获得完整的解释。
In C++ classes and structs are more or less the same. See the previous link I gave you for a full explanation.


这里的一些见解: [ ^ ]。







Some insight here: The real difference between struct and class[^].



Quote:

我也想知道为什么我们使用OOP而不是结构化编程,这太简单了,无法编写和理解我们在制作课程和其他人时不需要额外工作

And also i want to know that why we use OOP instead of structured programming which is too simple to write and understand and we don't need to work extra on making classes and others

C ++ 是一种多范式语言,如果愿意,你可以更好地使用它作为' C',遵循结构化编程原则。在我看来, OOP 有其优点,特别是在大型项目上。

C++ is a multi paradigm language, if like, you may use it as a 'better C', following structured programming principles. In my opinion OOP has its advantages, expecially on big projects.


这篇关于为什么我们使用类而不是结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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