Thread: object() and object;

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    630

    object() and object;

    Hello

    I've been having headaches for 2 days because I thought someobject o; is the same as someobject o();

    Now I wonder what is the difference betwen those two?

    My program was crashing because I had someobject o; which prevented the expected constructor behavior.

    When I changed it to someobject o(); everything worked as it should..

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    There shouldn't be a difference. Can you show some code?

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    630
    Sure..

    Inside main:

    client_session o; //will make it crash

    client_session o(); //this wont make it crash

    Code:
    class client_session {
    public:
    	client_session() :
    		_io_service(),
    		_client(_io_service, *this) { }
    	
    	boost::asio::io_service _io_service;
    	client _client;
    };
    
    class client : public connection {
    public:
    	client(boost::asio::io_service& io_service, client_session &session) :
    		connection(io_service),
    		_session(session) { }
    
    	client_session &_session;
    };
    
    class connection {
    public:
    	connection(boost::asio::io_service &io_service) : _socket(io_service) { }
    	boost::asio::ip::tcp::socket _socket;
    };

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by l2u View Post
    I've been having headaches for 2 days because I thought someobject o; is the same as someobject o();

    Now I wonder what is the difference betwen those two?
    The first declares an object 'o' of type someobject. The second declares a function 'o' which takes no parameters and returns a someobject.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. using this as synchronization object
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 03-22-2008, 07:49 AM
  2. synchronization object choosing
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 03-22-2008, 04:33 AM
  3. circular doubly linked list help
    By gunnerz in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2007, 08:38 PM
  4. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  5. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 04:24 PM