CppClass
[toc]
class
- The fundamental ideas behind classes are
data abstraction
andencapsulation
. - The only difference between classes and structs is the default visibility.
- Use the prefix
m_
to denote a private variable. - class can reduces duplication
e.g.
c++
1 |
|
Initializing a class
c++
1 | Entity e("Randolfluo"); //stack |
Allocate on the heap:
- Object really really binggggg!
- I want to explicitly control the lifetime of the object.
Inheritance
c++
1 |
|
Log class
c++
1 |
|
class lifetime
c++
1 |
|
constructor && destructor
Don’t forget initialization.
The constructor is automatically executed when the object is instantiated and does not need to be called manually.
- A class can have multiple constructors. Each constructor must differ from the others in the number or types of its parameters.
c++
1 |
|
virtual function
- Base on Dynamic Dispatch && v table,cause performance loss.
- Like java’s overwrite
c++
1 |
|
virtual destruction
- When the parent class pointer points to the child class, the correct fictitious function is called to prevent memory leaks
c++
1 |
|
//TODO
Initialization List
- Initializers help you get initialization done quickly
c++
1 |
|
->
c++
1 |
|
c++
1 |
|
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 Randolfluo's blog!