Skip to content

Instantly share code, notes, and snippets.

@max-dark
Created August 12, 2016 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save max-dark/3435fb42a7bc36d2d0f5e468bbfbd417 to your computer and use it in GitHub Desktop.
Save max-dark/3435fb42a7bc36d2d0f5e468bbfbd417 to your computer and use it in GitHub Desktop.
Создает алиас 'parent' для родительского класса
#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