61 - Template Specializations

#include 
using namespace std;

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

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

int main()
{
    spunky obj1(7);
    spunky obj2(7.143);
    spunky obj3('q');
}

你可能感兴趣的:(61 - Template Specializations)