C++ template specialization of constructor

后端 未结 7 891
醉话见心
醉话见心 2021-02-05 17:15

I have a templated class A and two typedefs A and A. How do I override the constructor for A ? The following does not wor

7条回答
  •  隐瞒了意图╮
    2021-02-05 17:34

    You can't with your current approach. one_type is an alias to a particular template specialization, so it gets whatever code the template has.

    If you want to add code specific to one_type, you have to declare it as a subclass of A specialization, like this:

      class one_type:
        public A
      {
        one_type(int m)
          : A(m)
        {
          cerr << "One type" << endl;
        }
      };
    

提交回复
热议问题