Skip to content

Instantly share code, notes, and snippets.

@ArtyomLazyan
Created December 8, 2017 16:40
Show Gist options
  • Save ArtyomLazyan/64a8e5e468d3fb03a3d0e3b7da0ac2d0 to your computer and use it in GitHub Desktop.
Save ArtyomLazyan/64a8e5e468d3fb03a3d0e3b7da0ac2d0 to your computer and use it in GitHub Desktop.
STATIC POLYmorphysm
/* 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