|
Boost : |
From: Roland Schwarz (roland.schwarz_at_[hidden])
Date: 2007-10-11 03:30:05
Zara wrote:
> class foo {
> private:
> unsigned char internals[5];
> public:
> char a() {return internals[0];}
> int b() {
> // select code block depending on your endianness
> unsigned int n=(a[0]<<24)|(a[1]<<16]|(a[2]<<8)|a[3];
> unsigned int n=(a[3]<<24)|(a[2]<<16]|(a[1]<<8)|a[0];
> return static_cast<int>(n);
> }
> };
Thank you for the answer, but the solution is only close to what I
requested.
Access syntax in your solution is:
data.a()
while I want
data.a
I.e. a has to be an object on its own that has a type conversion
operator for the access.
My problem as far as I can currently see, boils down to another question:
I have
struct bar
{
}
and
struct foo
{
bar a;
}
How can I give bar access to its "container"?
Perhaps like so:
struct foo
{
foo() {
a.setref(this);
}
bar a;
}
But this implies runtime cost, which I want to avoid.
Another solution:
struct foo
{
foo() : a(this) {}
bar a;
}
While I am not sure if this avoids the runtime cost, I am also unsure if
this is valid C++ at all. At least the microsoft compiler spills out a
warning.
Roland aka speedsnail
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk