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

前端 未结 7 1225
执笔经年
执笔经年 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:22

    Because bar contains a std::vector, not a std::vector *.

    It's really no different to something like this:

    class bar
    {
        int foo;  // No need to create a "new int"
    };
    

提交回复
热议问题