J
Jean-Claude Gervais
Hi,
I'm trying to write a template class that knows its own name.
Specifically, I want it to behave this way -
Say I instantiate a template class like this:
my_vector<int> foo;
I'd like to have a method (let's call it GetClassName) in my_vector that
returns a pointer to the string "int".
Or if the instantiation was done with any other class, like CPoint,
calling ClassName() would return "CPoint".
#define paster( n ) ( "class" #n " is the class" )
template <typename T> class my_vector : public std:vector<T> {
public:
static char * GetClassName(void) { return paster( T ); };
};
But I am having problems with doing this in a template. It seems like
the typename T is being taken literally as "T", the string returned is
always
"class T is the class"
Is there a way?
I'm trying to write a template class that knows its own name.
Specifically, I want it to behave this way -
Say I instantiate a template class like this:
my_vector<int> foo;
I'd like to have a method (let's call it GetClassName) in my_vector that
returns a pointer to the string "int".
Or if the instantiation was done with any other class, like CPoint,
calling ClassName() would return "CPoint".
#define paster( n ) ( "class" #n " is the class" )
template <typename T> class my_vector : public std:vector<T> {
public:
static char * GetClassName(void) { return paster( T ); };
};
But I am having problems with doing this in a template. It seems like
the typename T is being taken literally as "T", the string returned is
always
"class T is the class"
Is there a way?