I'm trying to provide a template argument with a const char* argument. My understanding is that you can provide a template argument with essentially an address, such as a function pointer and stuff like that. In this case I'd like to give it a pointer to an address holding a string, or char array, but it doesn't work:
constexpr const char* pString = "hello";
constexpr int* pToInt = nullptr;
// Am I right to have constexpr const char*? The constexpr says the pointer is const
// And the const before the char says the char is unmodifiable?
template <int* pToInt>
class TakeStaticIntPointer
{};
template <const char* pToString>
class TakeStaticStringPointer
{};
int main()
{
TakeStaticIntPointer<pToInt> myFoo; // Works fine
TakeStaticStringPointer<pString> myFoo2;
// Invalid non-type template argument of type const char*
}
I don't understand what's going on here. I'd also like to provide the template argument of a string literal "Hello". That's a compile-time constexpr, isn't it?