struct aliases

Kenny B funisher at gmail.com
Wed Nov 14 17:19:38 PST 2007


0ffh wrote:
> Jarrett Billingsley wrote:
>> almost:
>> [...]
>> Course those members could be put into a template and then mixed in. 
> 
> :-P

Dude, why didn't I ever think of unions! It's annoying to have to
duplicate all of the data definitions, but I suppose I don't mind it.

I used your first message, and it didn't quite work, but I arrived at
this: (it's the same thing... as Jarrett's)

class MyClass {
	struct Data {
		int val1;
		int val2;
	}
	
	union {
		Data data;
		struct {
			int val1;
			int val2;
		}
	}
}

The reason I have to preserve the Data array is because that class's
data gets filled from memcache. In memcache, that data is just a block
of bytes, so I copy the buffer from memcache into &data with
Data.sizeof... Once the data is copied, it's really nice to be able to
say MyClass.val1 :)

Again, THANK YOU SO MUCH... I pulled my brain for hours trying to think
of how.

Kenny


More information about the Digitalmars-d-learn mailing list