www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Alias to struct memembers of a function paramater as a shortcut => need this for XYZ of type void*

reply =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench saphirion.com> writes:
struct X {
	TYPE a;
	TYPE b;
}


myFunc(X _struct){
	alias a = _struct.a;

	a = myOtherFunc();
}


X myStruct;

myFun(myStruct);


This gives an error: need this for a of type void*

I don't understand why, because all I want is a shortcut the symbol of 
the parameter.

-- 
Robert M. MŁnch
http://www.saphirion.com
smarter | better | faster
Apr 07
parent reply ag0aep6g <anonymous example.com> writes:
On 07.04.19 14:23, Robert M. M√ľnch wrote:
 struct X {
      TYPE a;
      TYPE b;
 }
 
 
 myFunc(X _struct){
      alias a = _struct.a;
 
      a = myOtherFunc();
 }
 
 
 X myStruct;
 
 myFun(myStruct);
 
 
 This gives an error: need this for a of type void*
 
 I don't understand why, because all I want is a shortcut the symbol of 
 the parameter.
You can't make an alias to a field of an object. The alias will be made in relation to the type instead. (If that makes sense. I'm not sure how to phrase it best.) In code, this: alias a = _struct.a; is the exact same as this: alias a = X.a; The instance `_struct` is not part of the alias.
Apr 07
parent reply =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench saphirion.com> writes:
On 2019-04-07 14:05:13 +0000, ag0aep6g said:

 You can't make an alias to a field of an object. The alias will be made 
 in relation to the type instead. (If that makes sense. I'm not sure how 
 to phrase it best.)
The docs state that an alias can either be related to the type or the symbol. Hence, in my case I expected it to be the symbol... -- Robert M. MŁnch http://www.saphirion.com smarter | better | faster
Apr 07
parent ag0aep6g <anonymous example.com> writes:
On 07.04.19 17:36, Robert M. M√ľnch wrote:
 The docs state that an alias can either be related to the type or the 
 symbol. Hence, in my case I expected it to be the symbol...
The symbol is `X.a`. A field of an instance doesn't make a distinct symbol.
Apr 07