-2
#include <iostream>
using namespace std;

class Circle{
public:
 Circle(){ cout<<"im a circle\n"; }
 void operator+(){ cout<<"im a + operator\n"; }
};

int main()
{
  Circle();
  Circle();
  + 
  Circle();
}

output

"im a circle"

"im a circle"

"im a circle"

"im a + operator"

i want to receive output with this order

"im a circle"

"im a circle"

"im a + operator"

"im a circle"

I want as third output im a + operator. How can I fix this code so the output is in this specific order?

Praetorian
  • 106,671
  • 19
  • 240
  • 328
Lk2
  • 51
  • 1
  • 6

1 Answers1

1

To get the output wanted just write

int main()
{
  Circle a;
  Circle b;
  +a; 
  Circle c;
}

See a working demo.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • thanks! but is necessary to give only the "+" operator without a; – Lk2 Jan 11 '16 at 21:22
  • @therealp That's not a valid c++ expression, thus you are lost. Why is this needed actually? You can't call an operator without a concrete instance. – πάντα ῥεῖ Jan 11 '16 at 21:24
  • 1
    @therealp Oh, I'm surprised now. May be you could add another answer that shows how you actually fixed your code achieving the requirement stated in your 1st comment? I'm just curious. – πάντα ῥεῖ Jan 11 '16 at 21:32