当前位置:网站首页>On insect classes and objects
On insect classes and objects
2022-06-26 13:48:00 【Hua Weiyun】
Classes and objects
Preliminary understanding of process oriented and object-oriented
C Language is == Process oriented == Of ,== Focus on == Yes. == The process ==, Analyze the steps to solve the problem , Solve the problem step by step through the function call .
C++ yes == Based on object-oriented == Of ,== Focus on == Yes. == object ==, Split a thing into different objects , It depends on the interaction between objects
Class introduction
==C In language , Only variables can be defined in the structure , stay C++ in , Not only can variables be defined in a structure , You can also define functions ==
== such as c Define a stack in language ==
== and c++ Class is introduced in What is class Class is to define a new type ==
== Class consists of two parts :1. Member variables ( attribute )2. Member functions ( Behavior )==
==c++ Medium struct compatible c All uses of , meanwhile c++ Zhongba struct Upgrade to class ==
The definition of the above class ,== stay C++ I prefer to use class Instead of ==
This is why the definition of class in school is not struct, It is class
The definition of a class
class A{ // The class body : It consists of member functions and member variables }; // Like the structure, don't forget the semicolon==class== Define the of the class == keyword ==,==A Is the name of the class ==,=={} Is the body of the class ==, Be careful == Class definition ends with a semicolon ==.
The elements in the class are called == Class members ==: Class == data == be called == Attributes of a class == perhaps == Member variables ==; Class == function == be called == Class method == perhaps == Member functions ==.
Two ways to define classes
Declarations and definitions are all placed in the class body , We need to pay attention to : If a member function is defined in a class , The compiler may treat it as an inline function
The reason is .
The statement is placed in .h In file , The definition of a class is placed in .cpp In file
Class access qualifier and encapsulation
Access qualifier
C++ The way to achieve encapsulation :== Use classes to combine the properties and methods of objects , Make the object more perfect , Selectively provide its interface to external users through access rights ==
== Access qualifier description ==
- public Decorated members can be accessed directly outside the class
- protected and private Decorated members cannot be directly accessed outside the class ( here protected and private It's similar )
- The access scope is from == The position where the access qualifier appears begins until the next access qualifier appears ==
- class Of == The default access is private==,==struct by public==( because struct To be compatible with C)
Interview questions :c++ in struct and class What's the difference
C++ Compatibility required C Language , therefore C++ in struct It can be used as a structure . in addition C++ in struct It can also be used to define classes . and class Yes, the definition class is the same , The difference is that ==struct The default access method for members is public,class Yes, the default access method for members is private.==
Interview questions : Three characteristics of object-oriented encapsulation Inherit polymorphic
In fact, there are more than three characteristics such as == abstract Reflection ==
In the class and object phase , We only study == Class encapsulation features ==, What is encapsulation ?
== encapsulation ==: Organically combine data and methods of operating data , Hide object properties and implementation details , Only expose interfaces to interact with objects .
== Data and methods are encapsulated in classes , Manage , I want to define your access as shared , What you don't want to access is defined as private or protected ==
== Encapsulation is essentially management ==: How do we manage the terracotta warriors and horses ? For example, if you don't care about anything , The terracotta warriors and horses were destroyed at will . So we first built a house to encapsulate the terracotta warriors and horses . But our purpose is completely encapsulated , Don't let others see . So we opened the ticket channel , You can buy tickets and visit under a reasonable supervision mechanism . Class is the same , We use class data and methods encapsulated in .
What you don't want others to see , We use protected/private Encapsulate members . Open some common member functions for reasonable access to members . So encapsulation is essentially a kind of management .
边栏推荐
- Select tag - uses the default text as a placeholder prompt but is not considered a valid value
- Go language - pipeline channel
- Detailed sorting of HW blue team traceability process
- Logical operation
- [shell] generate strings between specified dates
- A collection of common tools for making we media videos
- MySQL explanation (I)
- Gurivat sprint Harbour Exchange listed: created “multiple first”, received 900 million yuan Investment from IDG capital
- MySQL configuration improves data insertion efficiency
- Lamp compilation and installation
猜你喜欢

MySQL explanation (I)

Zero basics of C language lesson 8: Functions

Wechat applet magic bug - choose to replace the token instead of clearing the token, wx Getstoragesync will take the old token value instead of the new token value

古瑞瓦特沖刺港交所上市:創下“多個第一”,獲IDG資本9億元投資

CloudCompare——泊松重建

Learn how to develop owl components by hand (7): practical use of owl projects

7.Consul服务注册与发现

Beifu PLC obtains system time, local time, current time zone and system time zone conversion through program

HW蓝队溯源流程详细整理

输入文本自动生成图像,太好玩了!
随机推荐
Applicable and inapplicable scenarios of mongodb series
Detailed practical sharing, two hours of funny videos after work, earning more than 7000 a month
33、使用RGBD相机进行目标检测和深度信息输出
Range of types
MySQL explanation (I)
Tips for using nexys A7 development board resources
[how to connect the network] Chapter 2 (next): receiving a network packet
Es6: iterator
【Spark】. Explanation of several icons of scala file in idea
Sed editor
Solutions to insufficient display permissions of find and Du -sh
ES中索引别名(alias)的到底有什么用
微信小程序注册指引
Embedded virlog code running process
Log in to the server using SSH key pair
A primary multithreaded server model
Es sauvegarde et restauration des données par instantané
MySQL configuration improves data insertion efficiency
es常用语法一
Mysql database explanation (6)





