Tuesday, May 15, 2012

Execution order when creating object inside function call


#include <iostream>

using namespace std;

struct A{
 
  A(){
    cout<<"A{"<<endl;
  }
  ~A(){
    cout<<"}A"<<endl;
  }

  int operator<<(int x){
    cout<<"<<"<<x<<endl;
    return x;
  }

};



void f(int x){
  cout<<"f("<<x<<")"<<endl;
}

int main(){
  f(A()<<3);
}


======OUTPUT======



A{
<<3
f(3)
}A


No comments:

Post a Comment