Last active
November 9, 2017 13:57
-
-
Save ndtimofeev/2bcef9e4118a5417f21d0308dd0160e2 to your computer and use it in GitHub Desktop.
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> | |
template <typename C> | |
struct Base | |
{ | |
static const int id; | |
static constexpr const char* const name = 0; | |
static void out(){ std::cout << "name: " << C::name << std::endl; } | |
}; | |
struct DerivedA : public Base<DerivedA> | |
{ | |
static const int id = 1; | |
static constexpr const char* const name = "DerivedA"; | |
}; | |
struct DerivedB : public Base<DerivedB> | |
{ | |
static const int id = 2; | |
static constexpr const char* const name = "DerivedB"; | |
}; | |
int main( int argc, char** argv ) | |
{ | |
DerivedA da; | |
DerivedB db; | |
std::cout << da.name << " " << db.name << std::endl; | |
std::cout << da.id << " " << db.id << std::endl; | |
std::cout << sizeof( da ) << " " << sizeof( db )<< std::endl; | |
da.out(); | |
db.out(); | |
std::cout << "That's all!" << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment