Thread: Constructor call difference

  1. #1
    Registered User
    Join Date
    Jul 2004

    Constructor call difference


    I have that test class

    class TestClass
    		std::cout << "Constructor" <<std::endl;
    		std::cout << "Deconstructor" << std::endl;
    int main()
    	//what is the difference between them 
    	TestClass rt; // show constructor, deconstructor output
    	TestClass rt1(); // does nothing
    	return 1;
    I am interested what is the difference between the two object declaration, because second declaration ( TestClass rt1(); ) seems to do nothing


  2. #2
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Cayman Islands
    TestClass rt1(); // does nothing

    Because the compiler thinks this is a function declaration

    rt1() is a function that takes no parameters and returns a TestClass.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Well the 2nd one looks like a prototype for a function called rt1, taking no parameters and returning a TestClass
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Incidentally, the more usual word for what you're calling "deconstructor" is "destructor".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Finding the difference in two times
    By muthus in forum C++ Programming
    Replies: 4
    Last Post: 01-24-2008, 06:36 PM
  2. Difference Equations / Recurrence Relations
    By DavidP in forum A Brief History of
    Replies: 4
    Last Post: 10-05-2007, 10:26 AM
  3. What's the difference between var++ and ++var
    By ulillillia in forum C Programming
    Replies: 6
    Last Post: 05-31-2007, 02:27 AM
  4. Replies: 6
    Last Post: 08-26-2006, 11:09 PM
  5. Difference between macro and pass by reference?
    By converge in forum C++ Programming
    Replies: 2
    Last Post: 02-26-2002, 05:20 AM