0

Hello Everybody,
I have a small doubt regarding how we can call constructors in a C++ class

class test
{
public:
       
      test()
      {
            cout<<"In test\n";
      }
};


int main() 
{
        test t1;
        test t2();    // This call does not give compile time error but does not call the constructor
	cin.get();
}

So my question is what exactly happens when the statement test t2() is executed. Why does this call not invoke the default constructor.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by abhimanipal
0

The compiler sees that line as a declaration of a function ( t2 ) which takes no arguments and returns an object of class test .

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.