How to declare data members that are objects of any type in a class

前端 未结 5 1818
夕颜
夕颜 2020-12-29 09:31

In this piece I\'m trying to declare in Class B a list that can hold objects of Class A of any type, such as A, A, A. I intend to add A

5条回答
  •  没有蜡笔的小新
    2020-12-29 09:41

    Member variables aren't allowed to be templates. Only member functions can be templates. You'll have to templatize the enclosing class B instead:

    template 
    class B {
      std::list*> objects;
    };
    

提交回复
热议问题