Wednesday 14 March 2007

Calling ctor!!

Well, suppose we have a class as below

class CTest
            cout<<"ctor called!";

int main()

Does it mean c'tor can be called without creating an object?

Nope!! ofcourse not!!

The reason is when CTest(); is called, the compiler inserts the code to create a tempory object of CTest and calls its c'tor. Also it destroys the object right after executing CTest(); statement.

That is the reason calling constructor inside another constructor is not valid.