I have learned that:
- Nontype template parameters carry some restrictions. In general, they may be constant integral values (including enumerations) or pointers to objects with external linkage.
So i made following code
1.
template <char const* name> class MyClass { … }; char const* s = "hello"; MyClass<s> x; // ERROR: This code didn't work and produce error 's' is not a valid template argument
My second code also didn't work
2.
template <char const* name> class MyClass { … }; extern char const *s = "hello"; MyClass<s> x; //error 's' is not a valid template argument` But strangely this code is fine
3.
template <char const* name> class MyClass { … }; extern char const s[] = "hello"; MyClass<s> x; // OK please tell what is happening in all of these three codes??
also tell how to correct errors to make other two codes working also.
const *vs* constchestnut...