Calling a subclass method causes a segmentation fault

This question already has an answer here:

  • What is The Rule of Three? 8 answers

  • The Grid class doesn't have a copy-assignment operator, so the compilers default generated version will be used instead. It's very simple, and does only a shallow copy of the members. That means that the pointers created for the temporary object Grid(4, 4) are copied (just the pointers, and not what they point to), and when the temporary object is destroyed so are the pointers (in the destructor for the temporary object). This leaves you with an object g with pointers to now deleted memory.

    I suggest you read about the rule of three.

    链接地址: http://www.djcxy.com/p/73186.html

    上一篇: 默认拷贝构造函数及其问题

    下一篇: 调用子类方法会导致分段错误