SORU
2 EKİM 2010, CUMARTESİ


Nasıl sonek ve önek için iki farklı şekilde operatör aşırı yükleme için?

Nasıl postfix için aşırı yükleme iki farklı şekilde operatör a a önek?

CEVAP
2 EKİM 2010, CUMARTESİ


Bu gibi görünmelidir:

class Number 
{
    public:
        Number& operator   ()     // prefix   
        {
           // Do work on this.   (increment your object here)
           return *this;
        }

        // You want to make the    operator work like the standard operators
        // The simple way to do this is to implement postfix in terms of prefix.
        //
        Number  operator   (int)  // postfix   
        {
           Number result(*this);   // make a copy for result
             (*this);              // Now use the prefix version to do the work
           return result;          // return the copy (the old) value.
        }
}; 

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Bart Baker

    Bart Baker

    1 Aralık 2006
  • Chilla Frilla™

    Chilla Frill

    7 Aralık 2006
  • tinycammonitor

    tinycammonit

    14 Aralık 2010