模板专业化-不确定为什么会出错

时间:2019-11-19 03:08:59

标签: templates compiler-errors specialization

我不确定为什么我的代码出错。我收到以下错误:第22行错误C2910:'Spunky :: {ctor}':无法显式专用,第26行错误C2514:'Spunky':类没有构造函数。这是我的代码:

#include <iostream>
#include <string>
using namespace std;

template <typename T>
class Spunky{
public:
    Spunky(T x){
        cout << x << " is not a character!" << endl;
    }
};

template<>
class Spunky<char>{
public:
    Spunky(char x);
};

template<>
Spunky<char>::Spunky(char x){
    cout << x << " is a character!" << endl;
}

int main()
{
    Spunky s(1);
    Spunky <char>d('a');

    system("pause");

    return 0;
}

0 个答案:

没有答案