Why doesn't C++ require a “new” statement to initialize std::vector?

前端 未结 7 1279
执笔经年
执笔经年 2021-02-01 13:42
/* bar.h */
class bar{
    /* standard stuff omitted */
    std::vector foo;
};

/* bar.cpp */
bar::bar(){ 
    // foo = new std::vector();         


        
7条回答
  •  旧巷少年郎
    2021-02-01 14:35

    std::vector foo is different from std::vector *foo. The second case will require you to use new while the first wll not.

提交回复
热议问题