I have the following code that compiles and works well:
template
T GetGlobal(const char *name);
template<>
int GetGlobal(cons
Though it is an old and outdated question, it may worth noting that C++11
had solved this issue using deleted functions:
template
T GetGlobal(const char *name) = delete;
template<>
int GetGlobal(const char *name);
UPDATE
This will not compile under MacOS llvm 8
.
It is due to a still hanging 4 years old defect (see this bug report).
The following workaround will fit the issue (using a static_assert
construct).
template
T GetGlobal(const char *name) {
static_assert(sizeof(T) == 0, "Only specializations of GetGlobal can be used");
}
template<>
int GetGlobal(const char *name);
UPDATE
Visual studio 15.9 has the same bug. Use the previous workaround for it.