Template specialization within class definition

前端 未结 2 576
醉酒成梦
醉酒成梦 2021-01-24 03:02

I wonder whether it is possible to put the whole code of such a class inside the class (kind of as in Java). I\'m doing this for some piece of code, instead of having to search

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-24 03:40

    Yes.

    It is completely possible though the specialization must be done in other template.

    #include 
    
    template  class A {
    public:
        A() {
            std::cout<<"Generic"< class A
    {
    public:
        A() { std::cout << "Bool specialization" << endl; }
    };
    
    int main(int argc, char** argv) {
        A a;
        A b;
    }
    

提交回复
热议问题