Objected oriented approach to structure inside structure
- by RishiD
This is for C++ but should apply to any OO language.
Trying to figure out the correct object oriented apporach to do the following (this is what I do in C).
struct Container {
enum type;
union {
TypeA a;
TypeB b;
};
}
The type field determines if it TypeA or TypeB object.
I am using this to handle responses coming back from a connection, they get parsed and get put into this structure and then based on the message type the appropriate fields get filled in.
e.g.
struct Container parseResponse(bufferIn, bufferLength);
Is there an OO approach for doing this?