template<typename T>
struct TFSS
{
static const char* FMT;
};
template<typename T>
const char* TFSS<T>::FMT = "%s";
template<>
struct TFSS<char>
{
static const char* FMT;
};
template<>
const char* TFSS<char>::FMT = "%hu";
template<>
struct TFSS<unsigned char>
{
static const char* FMT;
};
template<>
const char* TFSS<unsigned char>::FMT = "%hd";
代码编译出错
error C2998: “const char *TFSS<char>::FMT”: 不能是模板定义
error C2998: “const char *TFSS<unsigned char>::FMT”: 不能是模板定义
修改成如下代码
template<typename T>
struct TFSS
{
static const char* FMT;
};
template<typename T>
const char* TFSS<T>::FMT = "%s";
template<>
struct TFSS<char>
{
static const char* FMT;
};
const char* TFSS<char>::FMT = "%hu";
template<>
struct TFSS<unsigned char>
{
static const char* FMT;
};
const char* TFSS<unsigned char>::FMT = "%hd";
评论