[ create a new paste ] login | about

Link: http://codepad.org/PRYGdtZY    [ raw code | output | fork ]

Kodt - C++, pasted on Dec 21:
#define SHOWS() cout<<(void*)this<<" "<<__PRETTY_FUNCTION__<<endl;
struct A
{
  A() { SHOWS(); }
  ~A() { SHOWS(); }
  A(const A&) { SHOWS(); }
  operator const A&() const { SHOWS(); return *const_cast<A*>(this); }
};

A make() { return A(); }

int main()
{
  {
    cout << "construct:" << endl;
    A const& a = A();
    cout << "leaving the block..." << endl;
  }
  cout<<"-----"<<endl;
  {
    cout << "make:" << endl;
    A const& a = make();
    cout << "leaving the block..." << endl;
  }
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
construct:
0xbf9cec7a A::A()
0xbf9cec7a A::operator const A&() const
0xbf9cec7a A::~A()
leaving the block...
-----
make:
0xbf9cec4b A::A()
0xbf9cec4b A::operator const A&() const
0xbf9cec7b A::A(const A&)
0xbf9cec4b A::~A()
0xbf9cec7b A::operator const A&() const
0xbf9cec7b A::~A()
leaving the block...


Create a new paste based on this one


Comments: