Created
July 21, 2019 18:31
-
-
Save merryhime/5d3417019ccec2567ca9a7ddf0fe9060 to your computer and use it in GitHub Desktop.
This file contains 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
#include <cstdio> | |
class A { | |
public: | |
A() = default; | |
static void OverridableInit() { | |
std::printf("I am in A\n"); | |
} | |
protected: | |
template <typename T> | |
A(T* this_) { | |
T::OverridableInit(); | |
} | |
}; | |
class B : public A { | |
public: | |
B() : A(this) {} | |
static void OverridableInit() { | |
std::printf("I am in B\n"); | |
} | |
protected: | |
template <typename T> | |
B(T* this_) : A(this_) {} | |
}; | |
class C : public B { | |
public: | |
C() : B(this) {} | |
static void OverridableInit() { | |
std::printf("I am in C\n"); | |
} | |
protected: | |
template <typename T> | |
C(T* this_) : B(this_) {} | |
}; | |
int main() { | |
C c{}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment