2000

Grusel++ of the month

Home
Download Source
/******************************************************************************/
/*                                                                            */
/*                                                         FILE: FEBRUARY.CPP */
/*                                                                            */
/*  This is for educational purposes, YOU should not write code like this :-) */
/*  ========================================================================= */
/*                                                                            */
/*  Compiled and tested with Visual C++ V6.0                                  */
/*                                                                            */
/*  V1.00   17-FEB-2000   P. Tellenbach   http://www.heimetli.ch/             */
/*                                                                            */
/******************************************************************************/

#include <iostream.h>

class OP
{
 public:
    OP &operator++( int i )  { cout << *this ; return *this ; }
    OP &operator++()         { cout << " "   ; return *this ; }
    OP &operator+( int i )   { cout << i     ; return *this ; }
    OP &operator+()          { cout << " +"  ; return *this ; }
    OP &operator=( OP &o )   { cout << " = " ; return *this ; }
    operator int()           {               ; return   1   ; }
} op ;

int main( void )
{
 return ( op = +++op+++1 ) + 2 ;
}

Update 15. February 2020

I had to upgrade from iostream.h to iostream and add the using declaration to compile it without warnings or errors.

/******************************************************************************/
/*                                                                            */
/*                                                         FILE: FEBRUARY.CPP */
/*                                                                            */
/*  This is for educational purposes, YOU should not write code like this :-) */
/*  ========================================================================= */
/*                                                                            */
/*  Compiled and tested with Visual C++ V6.0                                  */
/*                                                                            */
/*  V1.00   17-FEB-2000   P. Tellenbach   https://www.heimetli.ch/            */
/*                                                                            */
/*  Compiled and tested with g++ V8.3.0                                       */
/*                                                                            */
/*  V2.00   15-FEB-2020   P. Tellenbach   https://www.heimetli.ch/            */
/*                                                                            */
/******************************************************************************/

#include <iostream>

using namespace std ;

class OP
{
 public:
    OP &operator++( int i )  { cout << *this ; return *this ; }
    OP &operator++()         { cout << " "   ; return *this ; }
    OP &operator+( int i )   { cout << i     ; return *this ; }
    OP &operator+()          { cout << " +"  ; return *this ; }
    OP &operator=( OP &o )   { cout << " = " ; return *this ; }
    operator int()           {               ; return   1   ; }
} op ;

int main( void )
{
 return ( op = +++op+++1 ) + 2 ;
}