61 - Template Specializations

2018-01-08  本文已影响0人  社交帐号直接注册
#include <iostream>
using namespace std;

template <class t>
class spunky
{
public:
    spunky(t x)
    {
        cout << x << " is not a character" << endl;
    }
};

template <>
class spunky<char>
{
public:
    spunky(char x)
    {
        cout << x << " is indeed a character" << endl;
    }
};

int main()
{
    spunky<int> obj1(7);
    spunky<double> obj2(7.143);
    spunky<char> obj3('q');
}
上一篇下一篇

猜你喜欢

热点阅读