当前位置:网站首页>Summary of knowledge points of objects and classes
Summary of knowledge points of objects and classes
2022-04-22 04:19:00 【holdtao】
1.OOP characteristic : abstract , Encapsulation and data hiding , polymorphic , Inherit , Code reusability
2. Class declaration and class method definition Class declarations describe data parts as data members , Describe the common interface with the method of member function . Class method definition : Describes how to implement class member functions .
3.C++ Interfaces are often ( Class definition ) Put it in the header file , Put the interface implementation in the source code . Common class names are capitalized .
4. Be careful ,class Declare a class , Pay attention to distinguish from the template , The template can be class typename Statement , Class, but not typename.
5. There are three kinds of permissions in the class :private public protected among protected Related to inheritance . and private Often data members .public Often member functions . The member function is the interface between data members and the outside world , bridge .
6. The only difference between structure and class is , The default value in the structure is public, The default in the class is private.
7. Inline function : Functions whose function definitions are in the class declaration will become inline functions . You can also define inline functions outside the class declaration , But it must be preceded by inline keyword .
class Stock
{
private:
void set_tot();
};
inline void Stock::set_tot()
{
total_val = shares * share_val;
}
8. Different objects of the same class have their own storage space -> There is its own member variable inside , But member functions are common to all objects of this class .
Class constructor and destructor
1. Because the data variable is private, No direct access , All classes cannot be initialized with the method of structure initialization .-> Class constructors are born .
2. Note the following points when using class constructors : The arguments to the constructor do not represent class members , But the values assigned to class members . Data member names generally use prefixes m_.
3. When designing a class , Generally, a default constructor that implicitly initializes all class members should be provided .
4. The destructor is added before the class name ~. commonly new After that, we will use the destructor delete Delete .
5.
Insert a code chip here
stock1 = Stock(“”,“”,“”)
Create a temporary variable assigned to stack1, But the destructor is called automatically when the temporary variable is not called .
6. The object created first calls destructor to delete base note. .
7. Initializing an object is more efficient than creating a temporary variable assignment to an object , Because there is no need to add another copy .
8.
Because some functions have no parameters in parentheses , Add... After the function const
void stock::show()const
matters needing attention :const Member objects can only be called const Member functions , When a member variable in a class +mutable after , Its value can be modified in constant objects and constant functions .
this The pointer
When two objects are involved , For example, it is used when comparing a data member of two objects this The pointer .
this Pointer to the object used to call the member function
1. When the return type is reference, it means that the calling object itself is returned , Not a copy .
2. Object array creation process : First create the object with the default constructor and save it in the array , Reuse stock{} Create temporary objects in , Then assign values to the elements in the array . All object arrays must have a default constructor when they are created .
Class scope :
Class scope means that members cannot be accessed directly from the outside , Class scope resolution operator must be added ::
版权声明
本文为[holdtao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210959451908.html
边栏推荐
- tensorflow报错:returned a result with an error set解决方案
- Implement joint type verification of parameters in nest
- Sumo circle driving
- L1-049 ladder race seat allocation (20 points)
- PowerDesiPowerDesigner导入sql 不显示表关联关系 怎么解决
- Tencent CSIG interview brief (passed)
- 01 knapsack problem (two-dimensional array solution and one bit array optimization)
- 调用函数时,关于传参那些事~
- Sr-te policy (Cisco) -- supplement
- 插一个数到排好序的数组中(冒泡+rand函数)
猜你喜欢

LeetCode_ Rectangle_ Difficulties_ 391. Perfect rectangle

pytorch使用profiler对模型性能分析时报错

Pytorch uses profiler to analyze the performance of the model

sqlilabs(25a-26)

Senet | attention mechanism - source code + comments

How do programmers ensure that software is free of bugs?

交通行业提升数据利用效率的核心是做好数据交换与共享

Autodesk genuine Service 2020 Supprimer

01-Read&Write

Cursor iterator mode
随机推荐
L1-049 ladder race seat allocation (20 points)
The United States raised interest rates and devalued the RMB, but such products ushered in a honeymoon period
Pytorch uses profiler to analyze the performance of the model
L1-047 sleep (10 points)
04-Functions
Why can sqlmap run the issue table but not the fields
How do I test the shuttle application? Unit test
Developing grpc application based on well-known micro service framework go micro
Introduction to Intel edge software center
Dynamic | hanging mirror safety R & D management system has passed CMMI3 international certification
专家有料 | 张祖优:腾讯云DevSecOps实践与开源治理探索
.net调试:使用visual studio调试dump文件
Web page performance optimization
Gaussian distribution -- Derivation in error measurement
Senet | attention mechanism - source code + comments
Autodesk Genuine Service2020删除
Anaconda related
How does IOT platform realize business configuration center
【近日力扣 】两数之和+相同的树
[machine learning] long and short term memory network (LSTM)