S
Steven T. Hatton
#include <iostream>
namespace ns{
const char name[] = "This is a Class Name";//won't compile
//char name[] = "This is a Class Name"; // compiles
template <typename T, char* Name_CA=name>
struct A {
A()
: _data(15)
, _name(Name_CA)
{}
T _data;
char* _name;
};
}
int main()
{
ns::A<int> a;
std::cout << a._name <<"\n";
return 0;
}
In function int main()
error: address of non-extern `ns::name' cannot be used as template
argument
I'm sure the explanation is buried somewhere in Clause 3 esoterica, but can
someone please explain in human readable form, why the version with const
char* won't compile?
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell
namespace ns{
const char name[] = "This is a Class Name";//won't compile
//char name[] = "This is a Class Name"; // compiles
template <typename T, char* Name_CA=name>
struct A {
A()
: _data(15)
, _name(Name_CA)
{}
T _data;
char* _name;
};
}
int main()
{
ns::A<int> a;
std::cout << a._name <<"\n";
return 0;
}
In function int main()
error: address of non-extern `ns::name' cannot be used as template
argument
I'm sure the explanation is buried somewhere in Clause 3 esoterica, but can
someone please explain in human readable form, why the version with const
char* won't compile?
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell