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