Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

(};|=

Name: Anonymous 2011-10-15 23:44


#include <iostream>

using namespace std;

class funzies {
  public:
    funzies(int value) : value_(value) {}
    ~funzies() {}

    funzies& operator++() {
      value_++;
      return *this;
    }

    funzies& operator++(int) {
      ++value_;
      return *this;
    }

    funzies& operator--() {
      value_--;
      return *this;
    }

    funzies& operator--(int) {
      --value_;
      return *this;
    }



    friend ostream& operator<<(ostream& stream, funzies& self) {
      return stream << self.value_;
    }
  private:
    int value_;
};

int main(int argc, char** argv) {
  funzies funfun(6);
  cout << funfun << endl;
  cout << ++funfun++ << endl;
  cout << ++++funfun++++ << endl;
  cout << ++--funfun--++ << endl;
  cout << --++--++--funfun--++--++-- << endl;
  return 0;
}


output:


6
8
12
12
10

Name: Anonymous 2011-10-16 1:25

Fuck the postfix operator for having stupid precedence. They should've only made the postfix operator, but given it the precedence of the prefix one.

You don't need to define the destructor if it doesn't do anything.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List