Re: Inheritance question
On 10/26/2010 11:36 AM, Andrea Crotti wrote:
I'm doing a project which has to manipulate some network data.
They suggested me to use the classical big buffer with the many memcpy,
but since we're in C++ I don't see why not using classes instead of
structs.
So I thought something like
--8<---------------cut here---------------start------------->8---
Packet:
char type;
const char *buffer;
What's the size? Why don't you simply use 'vector<char>'?
Beacon : Packet
int nr;
...
--8<---------------cut here---------------end--------------->8---
1. what does the "sizeof" return on a class exactly?
The size of the object, as compiler knows it. This is a compile-time value.
And (can I/does it make sense to) overload it?
You can't.
2. does it make sense to keep the pointer to the content in "Packet"?
Or would be better to create then another class
"PacketHeader" and then Packet is the sum of both
You know the algorithm you need to implement. We don't.
3. how would I pack the data?
something like?
void Packet::pack(const char *buffer) {
memcpy($first_field, ...)
What's the third argument to memcpy? Not sure what '$firs_field' is.
Weird syntax if you ask me.
}
Then of course the sanity checks for the dimension must be done
outside this
"Sanity checks"?
4. about inheritance, if I have a constructor like
Packet(char type, ..)
then I can implement it for example with
Packet::Packet(char type) : type(type)
right?
Yes.
But what should I then do then in Beacon?
What's the role of it?
Create one constructor with the same arguments seem to not work in
general...
Uh... Not sure what problem you're facing. Can you rephrase?
V
--
I do not respond to top-posted replies, please don't ask