嗨,我回来了几天。代码不相同,但类似于下面列出的内容:

     struct AB{

          vector<int> * temp;

          AB(){
              temp = new vector<int>;

          }

          AB(const AB &other){

                     temp = new vector<int> 
                    //and I am memberwise copying other.temp to temp. (Not shown here)
          }
         ~AB(){
                      delete AB;
          }
      };    
.

和在主课程中我正在做这个

      unordered_map<int, AB> mapOfAB;
      mapOfAB[0].temp->push_back(1);
.

这会给我一个分割错误,但如果我将临时作为堆栈(非动态)变量,它会运行正常。我希望我足够具体。

提前感谢

有帮助吗?

解决方案

You have a raw pointer, and you do not have an assignment operator. You have violated the Rule of Three.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top