Created
March 2, 2019 06:03
-
-
Save ming4883/1746d9569208c3d84e344511e84fe883 to your computer and use it in GitHub Desktop.
C++ Auto Register
This file contains hidden or 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> | |
//int a = 0; | |
template <typename T, T /*unnamed*/> | |
struct nnb_ForceInit { }; | |
template< | |
class T | |
> | |
class Scriptable { | |
public: | |
struct nnb_Proxy { | |
nnb_Proxy() { | |
std::cout << "Proxy was executed! ID: " << T::id() << std::endl; | |
//a++; | |
} | |
}; | |
static nnb_Proxy __nnb_proxy__; | |
typedef nnb_ForceInit<nnb_Proxy&, __nnb_proxy__> __nnb_typedef_dummy__; | |
} ; | |
template< | |
class T | |
> | |
typename Scriptable<T>::nnb_Proxy Scriptable<T>::__nnb_proxy__; | |
class Object : public Scriptable<Object> { | |
public: | |
static const char* id() { | |
return "[Object]"; | |
} | |
}; | |
class Image : public Scriptable<Image> { | |
public: | |
static const char* id() { | |
return "[Image]"; | |
} | |
}; | |
class Error : public Scriptable<Error> { | |
public: | |
static const char* id() { | |
return "[Error]"; | |
} | |
} ; | |
int main() { | |
std::cout << "Done " << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment