Created
September 22, 2020 16:25
-
-
Save Xenakios/1b9d0e327bfa8fac7371beb1c43ae8fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyBase | |
{ | |
public: | |
MyBase(int _x) : x(_x) {} | |
virtual ~MyBase() {} | |
virtual void say() = 0; | |
int x = 0; | |
private: | |
}; | |
class MyClassUser | |
{ | |
public: | |
MyClassUser(MyBase& _b) : b(_b) {} | |
MyBase& b; | |
}; | |
class MyDerived : public MyBase | |
{ | |
public: | |
MyDerived() : MyBase(42), user(*this) {} | |
void say() override | |
{ | |
std::cout << "MyDerived says " << x << "\n"; | |
} | |
MyClassUser user; | |
}; | |
void test_initlist() | |
{ | |
MyDerived d; | |
d.say(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment