C++ template class and operator overloading
This question already has an answer here:
Your assignment operator is broken. First you call delete on internal
, invalidating it. Then you call init
, which assigns to the elements of internal
. You need a reallocation between those two steps.
On another note, your copy constructor is broken too. Set internal
to nullptr
first. Otherwise, the assignment operator will be calling delete on an unititialized pointer.
On another note, your addition operator is broken. It assumes that the two arrays are the same size. If the second operand is bigger, you will have undefined behavior accessing elements that do not exist.
链接地址: http://www.djcxy.com/p/73152.html上一篇: 打印操作员超载失败?
下一篇: C ++模板类和运算符重载