Created
December 8, 2017 16:40
-
-
Save ArtyomLazyan/64a8e5e468d3fb03a3d0e3b7da0ac2d0 to your computer and use it in GitHub Desktop.
STATIC POLYmorphysm
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
/* STATIC POLYmorphysm */ | |
#include <iostream> | |
template<typename T> | |
class Base | |
{ | |
public: | |
void printName() | |
{ | |
static_cast<T*>(this)->printName(); | |
} | |
}; | |
class Backend : public Base<Backend> | |
{ | |
public: | |
void printName() | |
{ | |
std::cout << "This is a BackEnd\n" << std::endl; | |
} | |
}; | |
class FrontEnd : public Base<FrontEnd> | |
{ | |
public: | |
void printName() | |
{ | |
std::cout << "This is a FrontEnd\n" << std::endl; | |
} | |
}; | |
int main() | |
{ | |
Base<Backend> b; | |
b.printName(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment