show the importance of member initializer lists
This commit is contained in:
committed by
JamesFlare1212
parent
58b8a67d55
commit
3514476080
18
lectures/25_inheritance/constructor_test1.cpp
Normal file
18
lectures/25_inheritance/constructor_test1.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <iostream>
|
||||
|
||||
class Base {
|
||||
public:
|
||||
Base(int x) {
|
||||
std::cout << "Base constructor: " << x << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
class Derived : public Base {
|
||||
public:
|
||||
Derived(int x) : Base(x) { // member initializer list calls Base constructor
|
||||
std::cout << "Derived constructor" << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
int main(){
|
||||
}
|
||||
Reference in New Issue
Block a user