オペレータ=とコピーコンストラクタの間違った使い方
下のコードは永遠に、 Copy constructor called を出力し続ける、なぜか?どう直せばよいか?
class { public: int data; trouble() { data = 0; } trouble(const trouble &old); trouble operator = (const trouble old); } trouble::trouble(const trouble& old){ std::cout << "Copy constructor called\n"; *this = old; } trouble trouble::operator = (const trouble old){ std::cout << "Operator = called\n"; data = old.data; return (*this); } int main() { trouble t1; trouble t2(t1); return 0; }