-
name of a type
This is an oddity. I don't usually ask questions around here.
My issue is this, using macros you can do the following...
#define DOIT(typename) const char *typename ## _STR = #typename ;
DOIT(ClassName)
where DOIT(ClassName) will expand to the following...
const char *ClassName_STR = "ClassName";
My question is, can you do the equivalent with templates? Or some other way without using macros.
-
another possible approach is typeid
Kuphryn
-
thanks. that's a very good answer for the question that I asked. I'm afraid I asked the wrong question though.
What I have now, that I wish to replace is a macro that in addition to what I said above, does this:
DECLARE_A_STRUCT (structname,
int blah1;
int blah2;
float blah3;
)
and it expands to:
struct structname
{
int blah1;
int blah2;
float blah3;
};
const char *structname_str = "int blah1; int blah2; float blah3;";
The basic idea here is to provide a string version of the declared struct. I hate it of course. Any ideas?
-
The only way to do what you want involves macros. Or explicitly providing the string yourself eery time which, I presume, is what you wish to avoid.
-
that's what I thought. It's a sad attempt by me to mimic some of the "reflection" features of other languages.
-
CORBA libraries (or ORBS) and, IIRC, other systems like DCOM support reflection capabilities. They way they achieve that in in C or C++ involves code generation (eg mapping an interface specification to C++) or hard-coded types with defined library support. That is probably overkill for what you want -- it's intended to support a generic interface to distributed objects.