pointer to std::vector of arbitrary type (or any other templated class)

后端 未结 3 1578
时光取名叫无心
时光取名叫无心 2021-01-22 00:13

let\'s say i want to have a member variable for a pointer to std::vector but i do not want to specify what type of variable it stores. I want to access only those functions that

3条回答
  •  庸人自扰
    2021-01-22 00:52

    The line

    std::vector* myVec
    

    is not syntactically correct. One has to specify the type of the vector elements.

    You may want to do something on the line of

    template< typename T >
    class Foo{
      private:
        std::vector * myVec;
    };
    

    However, even that doesn't look nice, re-evaluating the design might be more important here.

提交回复
热议问题