Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <iostream>
- struct S{};
- template <typename T>
- class Base
- {
- public:
- Base()
- {
- //Init(); // Needs to call child
- }
- void Test()
- {
- Init();
- }
- virtual void Init() = 0;
- };
- class Child : public virtual Base<S>
- {
- public:
- virtual void Init()
- {
- printf("test\n");
- }
- };
- // Test pure-virtual method (make sure it's forcing)
- class Child2 : public virtual Base<S>
- {
- public:
- };
- int main()
- {
- Child foo; // Should print "test"
- Child2 foo2; // Does not compile - cannot initialize abstract class
- ((Base<S>*)&foo)->Init();
- foo.Test();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement