Inkrementacja
Operatory inkrementacyjne: przyrostkowy i przedrostkowy muszą zwracać stały obiekt, celem uniknięcia podwójnej operacji.

Przyrostek

C& C::operator++()
{
++member;
return *this;
}

Przedrostek

const C& C::operator++(int)
{
C tmp(*this);
++member;
return *tmp;
}

Przypisanie
Operator musi sprawdzać, czy po prawej stronie nie jest ten sam obiekt dla którego dokonuje się przypisania.

C& operator=(const C& rhs)
{
if (this == &rhs)
return *this;
member = rhs.member;
return &this;
}

0 Komentarzy

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany. Wymagane pola są oznaczone *