C++ : Vector of template class

后端 未结 4 1891
灰色年华
灰色年华 2020-12-10 04:39

I have a template class named Cell as follows:-

templateclass Cell
{
    string header, T data;
}

Now I want another class N

4条回答
  •  轮回少年
    2020-12-10 05:33

    Something like this?

    template
    class Row
    {
    private:
       std::vector > cells;
    };
    

    Okay, this answer is incorrect.

    So, if you want to store in one vector different cells - you should use some dynamic type identification (you can use one base-class and store pointer to it in vector, that use only virtual functions, that are overrided in all derived classes, you can store something like boost::any and save some type-identification for each inserted element, for cast them into real type and work with it).

提交回复
热议问题