• Announcements

Archived

This topic is now archived and is closed to further replies.

classes and structures

Recommended Posts

My question may concern OO programming. I would like to handle data in a structured way. Because I want to take advantage off C++ I want to use classes. My target platform is win32. My structure should have a finite(fix) size. The structure should be as compact as possible because it will have to transit over the internet. What I have done is the following:
  struct GENERIC { CHAR m_strName[13]; BYTE m_bData; etc. }; 
Then I’m using a class to handle it
  class CGeneric { public: CGeneric(); //operations virtual BOOL Create(void)=0; //members protected: GENERIC * m_struct; etc.. //destructor public: virtual ~CGeneric(); }; 
Then I’m using derivate structures /class. So when I need to send data I’m using the structure, and I use the class to manage it. What’s wrong / perfectible in this approach? Thank you for your help. DworD Edited by - dword2002 on February 22, 2002 5:18:37 AM Edited by - dword2002 on February 22, 2002 5:20:09 AM

Share on other sites
What''s wrong is the idea that you have split this across two classes when it is logically a single class. You see, a struct in C++ *is a* class, only with default access of public, whereas a class''s default is private. Additionally, you are using arrays as strings. Don''t do that, use std::string instead. You could rewrite it as:

  #include class CGeneric{public: // public membersprivate: std::string m_strName; char m_bData;};

As for transmitting this across the internet, you will need to come up with a serialisation strategy. Anything that goes across the internet has to achieve maximum portability. However, the data members of your class are stored in a platform dependent manner. You need to standardise on a platform independent representation of all the possible data types. Something like XML might be suitable.

Share on other sites
quote:
Original post by SabreMan
What''s wrong is the idea that you have split this across two classes when it is logically a single class. You see, a struct in C++ *is a* class, only with default access of public, whereas a class''s default is private. Additionally, you are using arrays as strings. Don''t do that, use std::string instead. You could rewrite it as:

  #include class CGeneric{public: // public membersprivate: std::string m_strName; char m_bData;};

As for transmitting this across the internet, you will need to come up with a serialisation strategy. Anything that goes across the internet has to achieve maximum portability. However, the data members of your class are stored in a platform dependent manner. You need to standardise on a platform independent representation of all the possible data types. Something like XML might be suitable.

As I said I need to have FIX size data structures (which eliminate the use of strings). As because I don''t want to store proc addresses in the structure it has to be a straight struct (without any c++). I want it to be as light as possible.

When I spoke about internet, I have been a bit unclear. The goal is not to be deployed as an internet solution, just to send packets trough. Much more trivial ƒº.

DworD

• Forum Statistics

• Total Topics
627743
• Total Posts
2978892

• 10
• 10
• 21
• 14
• 14