美文网首页
61 - Template Specializations

61 - Template Specializations

作者: 社交帐号直接注册 | 来源:发表于2018-01-08 20:33 被阅读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');
    }
    

    相关文章

      网友评论

          本文标题:61 - Template Specializations

          本文链接:https://www.haomeiwen.com/subject/ggcinxtx.html