www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - struct aliases

reply Kenny B <funisher gmail.com> writes:
Ok, I have reduced my code to a simple example... This is what I have:

class MyClass {
	struct Data {
		int val1;
		int val2;
	}
	
	Data data;
	void one_function() {
		// stuff
	}
}

MyClass c = new MyClass;
// I want to say this:
c.val1 = 5;

// not this:
c.data.val1 = 5;

---------------

I tried to alias the data.val1 val1 -- but it doesn't work. I know this
works though...

int val1;
alias val1 val2;

val2 = 5;
assert(val1 == val2);

How can I do that with the structs?

I'm using gdc 0.24 on x86_64

Thanks in advance,
Kenny
Nov 14 2007
parent Kenny B <funisher gmail.com> writes:
Kenny B wrote:
 Ok, I have reduced my code to a simple example... This is what I have:
 
 class MyClass {
 	struct Data {
 		int val1;
 		int val2;
 	}
 	
 	Data data;
 	void one_function() {
 		// stuff
 	}
 }
 
 MyClass c = new MyClass;
 // I want to say this:
 c.val1 = 5;
 
 // not this:
 c.data.val1 = 5;
 
 ---------------
 
 I tried to alias the data.val1 val1 -- but it doesn't work. I know this
 works though...
 
 int val1;
 alias val1 val2;
 
 val2 = 5;
 assert(val1 == val2);
 
 How can I do that with the structs?
 
 I'm using gdc 0.24 on x86_64
 
 Thanks in advance,
 Kenny

Ugh, thunderbird told me that there was a failure trying to copy the message to my sentbox, so it wanted to know if I wanted to send the message again. Sorry for the dup.
Nov 14 2007