Created
August 12, 2016 02:18
-
-
Save max-dark/3435fb42a7bc36d2d0f5e468bbfbd417 to your computer and use it in GitHub Desktop.
Создает алиас 'parent' для родительского класса
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 <iostream> | |
using namespace std; | |
template < | |
class T | |
> | |
/** | |
* @brief The Class struct | |
* | |
* Создает алиас 'parent' для родительского класса T | |
* Позволяет обращаться к методам родительского класса parent::methodName() | |
*/ | |
struct Class:public T{ | |
using parent = T; | |
}; | |
/** | |
* @brief The DemoParent class | |
*/ | |
class DemoParent { | |
protected: | |
void some(); | |
}; | |
/** | |
* @brief The ChildOne class | |
*/ | |
class ChildOne:public Class<DemoParent> { | |
public: | |
void some(); | |
}; | |
/** | |
* @brief The ChildNext class | |
*/ | |
class ChildNext:public Class<ChildOne> { | |
public: | |
void some(); | |
}; | |
int main() | |
{ | |
ChildNext one; | |
cout << "Hello World!" << endl; | |
one.some(); | |
return 0; | |
} | |
void DemoParent::some() { | |
cout << "Yo! [parent]" << endl; | |
} | |
void ChildOne::some() { | |
cout << "Yo! [One]" << endl; | |
parent::some(); | |
} | |
void ChildNext::some() | |
{ | |
parent::some(); | |
cout << "Yo! [Next]" << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment