Jump to content
  • Advertisement
Sign in to follow this  
Driv3MeFar

Inheritance, order, and packets

This topic is 4340 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

This should be a simple question. So at the moment I have my packet structure set up something like this for my game: struct stNetHeader { ... }; struct stNetGameMessage : public stNetHeader { ... }; My question is, when I create a stNetGameMessage, and copy it into a buffer for sending, or when I recieve a buffer to be coppied into an empty message, does the base class(/struct) get copied in first, then the derived, or vise versa? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Fruny
note though that if your structure isn't a POD type, its internal structure is undefined.


"In addition, a POD type can't have constructors, virtual functions, base classes, or an overloaded assignment operator."

Wouldn't that mean that my message's internal structure is undefined, since it has a base class?

Thanks for the heads up...time to remove my c-tors and assignment operators.

[Edited by - Driv3MeFar on July 5, 2006 8:40:03 PM]

Share this post


Link to post
Share on other sites
Yes, you can do something like this though:

struct MessageHeader
{
//...
};

struct MessageX
{
MessageHeader header;
};

In practice virtual functions and/or virtual inheritence are usually the only things that prevent a compiler from using POD layout.

You also need to pack the struture if you are going to put it on the wire:
#pragma pack(push, 1)
struct Message
{
//...
};
#pragma pack(pop)

Share this post


Link to post
Share on other sites
In reality, as long as you don't have a virtual function, and don't have more than one class, the layout will be "base class -> derived class". Your initial suggestion will work on any compilers/platforms you're likely to encounter (including GCC for x86, x86-64 and PPC, and MSVC for x86 and x86-64).

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!