/******************************************************************************/
/* */
/* 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 */
/* */
/******************************************************************************/
#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 ;
}
Update 28. February 2025
The program needed no change, but I corrected the return value.
/******************************************************************************/
/* */
/* 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 */
/* */
/* Compiled and tested with g++ V11.2.0 */
/* */
/* V2.10 28-FEB-2025 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 == 0 ;
}