How can I create a template instance which has a char* as argument?
I tried:
template <const char* const N1,typename T1>
class name_value_pair{
T1& val;
name_value_pair(T1& valx) : val(valx) {}
print(){
cout << N1 << "=" << val << endl;
}
};
int main(){
string alpha="123";
name_value_pair<"alpha",ty
peof(alpha
)> x(alpha);
x.print();
return 0;
}
...but this results in (g++):
string_templates.cpp:18: error: string literal "alpha" is not a valid template argument because it is the address of an object with static linkage
Using const char[] instead doesn't work - same error.
Ideas, anyone?
Stefan
Start Free Trial