Jump to content
  • Advertisement
Sign in to follow this  
nuclear123

Making an Object with no member variables?

This topic is 2705 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

say i have the following class

class socketConnection
{
private:
// none
public:
socketConnection();
~socketConnection();
// more member FUNCTION only
};


the above code contains no member attributes(such as int,string,float,double...etc). Is it perfectly legal to instantiate objects without private members for the reason being so i can put them in a linked list, so i know how many socketconnections i have open!? or is there another design patter that would work in the place of this?

It's nice to be able to treat items as objects so u can put them in a linked list and that it why i shoved them into a class

Share this post


Link to post
Share on other sites
Advertisement

It's valid, but why not just have:int numOpenSockets;


I agree with hodgman...a simple counter might do the job...also correct me if I'm wrong but the count member function of a list hast log n speed...a counter..well is just reading from a memory location...an atomic operation....

Share this post


Link to post
Share on other sites
You can do this... but surely you could think of useful members to store? An obvious example is IP address:port combination (UDP) or socket endpoint (TCP) or API connection reference. Other information you might want if you aren't using an API might be the last time you received activity from a peer, information about connection quality (for UDP), incomplete received message buffers, queues of unacknowledged packets (UDP). A reference to a game object controller of some kind, for writing the new input state.

The number of active connections can be inferred from the size() of the container storing the above. You'll need this kind of thing eventually, after all it isn't much good to know that you have 10 remote peers if you've forgotten the information needed to communicate with them!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!