C++ string template argument
Posted January 7th, 2005 . No Comments .
There is a pretty cool and sometimes useful way to pass strings as a template argument as shown in the example bellow:
#include <iostream> template<const char* name> class foo { const char* val; public: foo(): val( name ) { } const char* value( void ) { return val; } }; extern const char exname[] = "hello world"; int main(int, char** ) { foo< exname > myfoo; std::cout << myfoo.value() << std::endl; }
