Прокомментируйте ошибку пожалуйста.
От: Аноним  
Дата: 30.07.05 07:18
Оценка:
using namespace std;

class Simple
{
public:
    int a;

    Simple()
    {
        cout << "Constructor\n";
        a=10;
    }
    Simple(int b)
    {
        cout << "Constructor with int\n";
        a=b;
    }
    Simple(const Simple& b)
    {
        cout << "Constructor copy\n";
        *this=b;
    }
    Simple& operator= (const Simple& c)
    {
        cout << "Operator =\n";
        if(this!=&c) *this=c;    // Здесь ошибка
        return *this;
    }

    void print() const
    {
        cout << a << "\n";
    }

};

int main()
{
    Simple temp(56);
    Simple temp2=temp;

    temp2.print();

}


Ошибка понятна, но поведение странное —
Operator =
Operator =
Operator =
.... ~100 раз
Operator =
Press any key to continue
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.