Hi all,
I guess this is more of a design problem than a language problem, but
I'm confused either way! I have a class and it has a private data member
which is a struct. The size of the struct is what I would call relatively
large (about 1Mb). I have written methods for this class so that the struct
can be correctly filled with the corerct data and certain parts of the
struct can be extracted. But the problem I face is that I now have another
class that will also hold a private data member of the same struct, but this
class will work on the struct in a very different way. The thing I can't
resolve is that I want to transfer the contents of the struct from one class
to the other ... these are my ideas of how to do it but I don't know which
is best to use!
1. I could have a 'GetStruct' method which would return a const reference to
my private struct and then have my second class use memcpy to fill its
struct. For some reason I feel nervous giving out any reference to a private
member as it doesn't take much to defeat the 'constness' and mess around
with the internal struct ... I've had someone do that before with my code
before!
2. I could write a helper class that behaves rather like an STL iterator. I
could then get 'iterators' to the begining and end of my struct and transfer
it byte by byte. If possible I want to avoid using the STL itself because
this code may well end up in an embedded system and my customer isn't keen
on STL (despite my protesting!).
I'm sure this is a fairly standard problem that people come across all the
time, can anyone suggest the prefered/best method for doing this - oh and I
want to try and keep things as quick as possible.
Thanks,
Rich.