c语言面向对象编程中的类_C ++中的面向对象编程
c语言面向对象编程中的类
Object oriented programming, OOP for short, aims to implement real world entities like inheritance, hiding and polymorphism in programming.
面向对象的编程,简称OOP,旨在在编程中实现诸如继承,隐藏和多态性之类的现实世界实体。
The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function.
OOP的主要目的是将数据和对其进行操作的功能绑定在一起,以便除该功能外,代码的其他任何部分都无法访问此数据。
Let's learn about different characteristics of an Object Oriented Programming language.
让我们了解一下面向对象编程语言的不同特征。
目的: (Object:)
Objects are basic run-time entities in an object oriented system. Objects are instances of a class which are user defined data types.
对象是面向对象系统中的基本运行时实体。 对象是类的实例,是用户定义的数据类型。
class person
{char name[20];int id;
public:void getdetails(){}
};int main()
{person p1; //p1 is an object
}
Objects take up space in memory and have an associated address like a record in pascal or a structure or union in C.
对象占用内存中的空间,并具有关联的地址,例如pascal中的记录或C中的结构或联合。
When a program is executed the objects interact by sending messages to one another.
执行程序时,对象通过相互发送消息进行交互。
Each object contains data and code to manipulate the data. Objects can interact without having to know the details of each others' data or code. It's enough to know the type of message accepted and type of response returned by the objects.
每个对象都包含数据和用于操纵数据的代码。 对象可以进行交互,而不必知道彼此数据或代码的详细信息。 知道接受的消息类型和对象返回的响应类型就足够了。
类: (Class:)
A class is a blueprint of data and functions or methods. Class does not take any space.
类是数据,函数或方法的蓝图。 类不占用任何空间。
class class_name
{private://data members and member functions declarationspublic://data members and member functions declarationsprotected://data members and member functions declarations
};
Class is a user defined data type like structures and unions in C.
类是用户定义的数据类型,例如C中的结构和联合。
By default class variables are private, but in case of structure they are public. In the above example, person is a class.
默认情况下,类变量是私有的,但是在结构的情况下,它们是公共的。 在上面的示例中,person是一个类。
封装和数据抽象: (Encapsulation and Data abstraction:)
Wrapping up (combining) data and functions into a single unit is known as encapsulation. The data is not accessible to the outside world and only those functions which are wrapping the class can access it. This insulation of the data from direct access by the program is called data hiding or information hiding.
将数据和功能包装(组合)为单个单元称为封装。 外界无法访问该数据,只有包装该类的那些函数才能访问它。 防止程序直接访问的这种数据隔离称为数据隐藏或信息隐藏。
Data abstraction refers to providing only needed information to the outside world and hiding implementation details.
数据抽象是指仅向外界提供所需的信息并隐藏实现细节。
For example, consider a class Complex with public functions getReal() and getImag(). We may implement the class as an array of size 2 or as two variables.
例如,考虑具有公共函数getReal()和getImag()的类Complex。 我们可以将类实现为大小为2的数组或两个变量。
The advantage of abstraction is that we can change implementation at any point and the users of the Complex class won’t be affected as our method interface remains same. Had our implementation been public, we would not have been able to change it.
抽象的优点是我们可以随时更改实现,并且由于我们的方法接口保持不变,因此不会影响Complex类的用户。 如果我们的实施是公开的,我们将无法对其进行更改。
遗产: (Inheritance:)
Inheritance is the process by which objects of one class acquire the properties of objects of another class. It supports the concept of hierarchical classification.
继承是一个类的对象获取另一类的对象的属性的过程。 它支持层次分类的概念。
Inheritance provides reusability. This means that we can add additional features to an existing class without modifying it.
继承提供了可重用性。 这意味着我们可以在不修改现有类的情况下添加其他功能。
多态性: (Polymorphism:)
Polymorphism refers to the ability to take more than one form. An operation may exhibit different behaviors in different instances. The behavior depends on the types of data used in the operation.
多态性是指采取多种形式的能力。 一个操作在不同情况下可能表现出不同的行为。 行为取决于操作中使用的数据类型。
C++ supports operator overloading and function overloading. Operator overloading is the process of making an operator exhibit different behaviors in different instances. Function overloading is using a single function name to perform different types of tasks. Polymorphism is extensively used in implementing inheritance.
C ++支持运算符重载和函数重载。 操作员重载是使操作员在不同情况下表现出不同行为的过程。 函数重载使用单个函数名来执行不同类型的任务。 多态被广泛用于实现继承。
动态绑定: (Dynamic Binding:)
In dynamic binding, the code to be executed in response to a function call is decided at runtime. C++ has virtual functions to support this.
在动态绑定中,将在运行时确定响应函数调用而执行的代码。 C ++具有支持此功能的虚函数。
讯息传递: (Message Passing:)
Objects communicate with one another by sending and receiving information to each other. A message for an object is a request that a procedure be executed and therefore it will invoke a function in the receiving object that generates the desired results.
对象通过相互发送和接收信息来相互通信。 对象的消息是对过程执行的请求,因此它将在接收对象中调用生成所需结果的函数。
Message passing involves specifying the name of the object, the name of the function and the information to be sent.
消息传递涉及指定对象的名称,函数的名称以及要发送的信息。
更多信息 (More information)
Object Oriented Programming Concepts: How to go from Zero to One with Objects
面向对象的编程概念:如何使对象从零变为一
How to Explain Object Oriented Programming Concepts to a 6 Year Old
如何向6岁的孩子介绍面向对象的编程概念
翻译自: https://www.freecodecamp.org/news/object-oriented-programming-in-c/
c语言面向对象编程中的类
相关文章:

Maven build标签
前言: <build >设置,主要用于编译设置 1.分类 在Maven的pom.xml文件中,存在如下两种<build>: (1)全局配置(project build) 针对整个项目的所有情况都有效 (2…

Ant Design Vue 表格内编辑(附完整源码及效果图)
效果图: 实现关键代码就是表单的 columns 属性对象下标的 scopedSlots: scopedSlots: {customRender: } 实现完整代码: <template><div><div class"table-wrapper"><!--每个列的宽度必须比列名总长度大才能…

shell基本用法
#!/bin/bash #使用哪个shell执行echo "hello world" username"tom" echo $username#chmod x ./test.sh 设置可以执行文件#for循环输出 for skill in Ada Coffe Action Java; doecho "I am good at ${skill}Script" done #for file in ls /etc; d…

brad wu_一百万归功于Brad Traversy
brad wuBrad Traversy is one of the most appreciated web development teachers on YouTube and he is getting close to 1 Million subscribers. We decided to help him reach this goal by the end of 2019.布拉德特拉弗西 ( Brad Traversy)是YouTube上最受赞赏的网络开发…

CSS常见布局解决方案
最近要准备移动端项目,大半年没好好写过CSS了,今天恶补了一下CSS的一些布局,下面做一些分享。 水平居中布局 1.margin 定宽 <div class"parent"><div class"child">Demo</div> </div><style…

java.io.EOFException java.io.ObjectInputStream$PeekInputStream.readFully 错误
omcat 启动时报以下错误: java.io.EOFException at java.io.ObjectInputStream$PeekInputStream.readFully 错误 这个错误 碰到好几次了,我的tomcat使用非常频繁,而且部署项目比较多,经常会出一些自己看不懂的问题, 今天解决了这…

SQL替换字段中部分字符
示例: tb_item表中image字段中一数据为:jd/4ef8861cf6854de9889f3db9b24dc371.jpg update tb_item set image replace(image,jd,taobao); 替换后: taobao/4ef8861cf6854de9889f3db9b24dc371.jpg

flexbox_Flexbox中的Flex基础属性
flexbox弹性基础 (Flex Basis) The flex-basis property defines the size of the flex-item along the main axis of the flex container. The main axis is horizontal if flex-direction is set to row and it’ll be vertical if the flex-direction property is set to co…

OpenStack之虚拟机热迁移
这里的环境是centos7版本,openstack K版 1.在各个计算节点设置权限 chmod 755 /var/lib/nova/instances 2.修改各个节点的nova.conf(/etc/nova/nova.conf) vncserver_proxyclient_address虚拟机IP # vncserver_listen0.0.0.0 3.修改所有计算节点libvirt 3.1 修改/e…

软件工程概论个人作业02
可怜的二柱子同学,老师又对他的自动出题系统提出了新的要求: 1、题目避免重复; 2、可定制(数量/打印方式); 3、可以控制下列参数: 是否有乘除法; 是否有括号(最多可以支持十个数参与计算)&#…

前端开发学习常用网站网址及介绍(都是免费的)
在开发的时候,想记住所有的单词基本是不可能的,所以就需要进入文档,只要理清需求能做出来,就很不差了!! 扫码加博主微信 1.百度,俗称度娘,有不懂的就问百度,有问必答&am…

sql语句语法多表关联_SQL Delete语句-如何删除行或表,语法示例
sql语句语法多表关联To delete a record in a table you use the DELETE statement.要删除表中的记录,请使用DELETE语句。 Be careful. You can delete all records of the table or just a few. Use the WHERE condition to specify which records do you wan…

数据库 大数据访问及分区分块优化方案
本文导读:当系统要满足每秒数万次的读写请求的需求时,我们可以用分布式计算、编写优良的程序代码、对海量数据进行分区操作、建立广泛的索引、建立缓存机制、加大虚拟内存、分批处理、使用数据仓库和多维数据库存储、使用负载均衡技术、将数据库的读写分…

每周算法讲堂 floyd
http://www.bilibili.com/video/av4108914/ 转载于:https://www.cnblogs.com/qscqesze/p/5284554.html

小程序云开发常用语句宝库
查询语句,返回的是 res.data[] 数组 调用云函数返回的是res.result get 数据获取返回的是 res.data{} 对象 1.调用云函数 this.DB wx.cloud.database() wx.cloud.init({env: mm-4t7rg }) wx.cloud.callFunction({name: "login",data: {},success(res)…

初学api测试_面向初学者的API-在此免费视频课程中学习如何使用API
初学api测试What exactly is an API? How do you use an API? Weve just published a full beginners course about Application Programming Interfaces (APIs) on the freeCodeCamp.org YouTube channel.API到底是什么? 您如何使用API? 我们刚刚…

整理Simple.Data使用方法
官方:http://simplefx.org/simpledata/docs/index.html Insert var user db.Users.Insert(Name: "Ford", Password: "hoopy", Age: 29);var user new User {Name "Zaphod", Password "zarquon", Age 42}; var actual db.Users.I…

css3之border-radius理解
在日常项目过程中,border-radius这个属性算是非常常用的属性之一了,通过设置元素的border-radius值,可以轻松给元素设置圆角边框,甚至实现绘制圆、半圆、四分之一的圆等各种圆角图形。 通常我在使用这个属性的时候,一般…

deepLink iOS 应用到自己APP 记录
1.了解deeplink 详细的介绍可以在网上查询,这里简单说一下.这项技术主要是为了方便广告跳转而产生的.最大的例子就是淘宝,天猫,京东等购物APP.在第三方APP中点击广告链接直接跳转到对应的客户端的商品的详情中,节省用户的时间,一步到位. 2.自己APP实现deeplink需要的准备工作…

小程序 reduce_使用reduce制作的10个更多实用程序功能
小程序 reduceThis time, with a test suite! 这次,带有测试套件! Previously I wrote about 10 utility functions implemented with JavaScripts reduce function. It was well-received, and I walked away with an even deeper appreciation for th…

洛谷1216 数字三角形
题目描述 观察下面的数字金字塔。 写一个程序来查找从最高点到底部任意处结束的路径,使路径经过数字的和最大。每一步可以走到左下方的点也可以到达右下方的点。 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 在上面的样例中,从7 到 3 到 8 到 7 到 5 的路径产生了最大 …

iOS 依次执行 异步网络请求的一种实现
1.首先先介绍一个概念dispatch_semaphore dispatch_semaphore信号量为基于计数器的一种多线程同步机制。用于解决在多个线程访问共有资源时候,会因为多线程的特性而引发数据出错的问题.如果semaphore计数大于等于1,计数-1,返回,程…

那些有趣的Webview细节
最近公司的项目"一步"上用到了webview与js交互,主要是用google地图必须要安装有google pay,但是国内的手机都去掉了, 没办法只有用google地图的网页版了, 好在公司ios的小伙伴会h5,英语也不赖, 所…

二进制搜索树_二进制搜索树数据结构举例说明
二进制搜索树A tree is a data structure composed of nodes that has the following characteristics:树是由具有以下特征的节点组成的数据结构: Each tree has a root node (at the top) having some value. 每棵树都有一个具有某些值的根节点(在顶部)。 The roo…

无序数组及其子序列的相关问题研究
算法中以数组为研究对象的问题是非常常见的. 除了排序大家经常会遇到之外, 数组的子序列问题也是其中的一大分类. 今天我就对自己经常遇到的无序数组的子序列相关问题在这里总结一下. 前置条件: 给定无序数组. 以下所以的问题均以此为前置条件. 例如无序数组nums [2, 1, 3]. 问…

IOS使用正则表达式去掉html中的标签元素,获得纯文本
IOS使用正则表达式去掉html中的标签元素,获得纯文本 content是根据网址获得的网页源码字符串 NSRegularExpression *regularExpretion[NSRegularExpression regularExpressionWithPattern:"<[^>]*>|\n"options:0error:nil];content[regularExpretion string…

苹果禁止使用热更新 iOS开发程序员新转机来临
今天本是女神们的节日,所有iOS程序员沸腾了!原因是苹果爸爸发狠了,部分iOS开发者收到了苹果的这封警告邮件: [图一 苹果邮件] 消息一出,一时间众多开发者众说纷纭,以下是来源于网络的各种看法:…

Python中的Lambda表达式
Lambda表达式 (Lambda Expressions) Lambda Expressions are ideally used when we need to do something simple and are more interested in getting the job done quickly rather than formally naming the function. Lambda expressions are also known as anonymous funct…

JAVA-初步认识-第十一章-object类-equals方法覆盖
一. 现在要谈论equals方法另一个方面。如果不写equals方法,直接用来比较也是可以的,貌似equals方法有点多余。 现在不比较对象是否相等,而是比较对象中的特定内容,比如说对象的年龄,之前的写法如下 其实这个方法写完后…

JPPhotoBrowserDemo--微信朋友圈浏览图片
JPPhotoBrowserDemo Browse picture like WeChat. GithubDemo 使用 CocoaPods pod JPPhotoBrowser 在使用的页面中 引用 #import "JPPhotoBrowserManager.h"下载使用 直接将下载文件中的 JPPhotoBrowser 文件夹拖入项目中在使用的页面中 引用 #import "JPPhot…