A
Andrea Crotti
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;
Beacon : Packet
int nr;
...
--8<---------------cut here---------------end--------------->8---
1. what does the "sizeof" return on a class exactly?
And (can I/does it make sense to) overload it?
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
3. how would I pack the data?
something like?
void Packet:ack(const char *buffer) {
memcpy($first_field, ...)
}
Then of course the sanity checks for the dimension must be done
outside this
4. about inheritance, if I have a constructor like
Packet(char type, ..)
then I can implement it for example with
Packet:acket(char type) : type(type)
right?
But what should I then do then in Beacon?
Create one constructor with the same arguments seem to not work in
general...
Thanks a lot,
Andrea
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;
Beacon : Packet
int nr;
...
--8<---------------cut here---------------end--------------->8---
1. what does the "sizeof" return on a class exactly?
And (can I/does it make sense to) overload it?
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
3. how would I pack the data?
something like?
void Packet:ack(const char *buffer) {
memcpy($first_field, ...)
}
Then of course the sanity checks for the dimension must be done
outside this
4. about inheritance, if I have a constructor like
Packet(char type, ..)
then I can implement it for example with
Packet:acket(char type) : type(type)
right?
But what should I then do then in Beacon?
Create one constructor with the same arguments seem to not work in
general...
Thanks a lot,
Andrea