Here is my problem: in the header, I define a structure template type_to_stringthat aims to define a string that matches a given type argument:
namespace foo {
template <typename T>
struct type_to_string
{
static const char * value;
};
}
template <typename T>
const char * foo::type_to_string<T>::value = "???";
I also define the default value for the string.
Now I want to use a macro to define new types:
#define CREATE_ID(name) \
struct name; \
\
template<> \
const char * foo::type_to_string<name>::value = #name;
The problem is that I would like to use a macro in namespaces, for example:
namespace bar
{
CREATE_ID(baz)
}
which is impossible because it type_to_string<T>::valueneeds to be defined in the namespace spanning foo.
Here are the compilation errors that I get:
[COMEAU 4.3.10.1] error: member "foo::type_to_string<T>::value [with T=bar::baz]"
cannot be specialized in the current scope
[VISUAL C++ 2008] error C2888: 'const char *foo::type_to_string<T>::value' :
symbol cannot be defined within namespace 'bar'
with
[
T=bar::baz
]
Oddly enough, GCC 4.3.5 (MinGW version) does not cause errors.
- , , , (.. type_to_string , - )?