August 30, 2009 D2 Pointer confusion | ||||
---|---|---|---|---|
| ||||
Hey guys, I got a problem with the following code: void main() { struct SomeStruct { int aa; } class SomeClass { int a; SomeStruct foo() { SomeStruct m; m.aa=a; return m; } } SomeClass inst=new SomeClass(); inst.foo.aa=20; assert(inst.a==20); } How can I make D set the member variable 'a' of SomeClass via this construction to another value? And what's with using "ref SomeStruct foo() {}"? Thanks in advance! ------------------------------------------------------------------------------ PS: Check out my D-IDE at http://www.alexanderbothe.com/?id=27 |
September 01, 2009 Re: D2 Pointer confusion | ||||
---|---|---|---|---|
| ||||
Posted in reply to A Bothe | Umm.. A shot in the dark?
void main(){
struct SomeStruct{
int* p;
void aa(int a){
*p = a;
}
}
class SomeClass{
int a;
SomeStruct foo(){
SomeStruct m;
m.g = &a;
return m;
}
}
SomeClass inst = new SomeClass;
inst.foo.aa = 20;
assert(inst.a == 20);
}
A Bothe wrote:
> Hey guys,
> I got a problem with the following code:
>
> void main()
> {
> struct SomeStruct
> {
> int aa;
> }
>
> class SomeClass
> {
> int a;
>
> SomeStruct foo()
> {
> SomeStruct m;
> m.aa=a;
> return m;
> }
> }
>
> SomeClass inst=new SomeClass();
> inst.foo.aa=20;
>
> assert(inst.a==20);
> }
>
>
> How can I make D set the member variable 'a' of SomeClass via this construction to another value? And what's with using "ref SomeStruct foo() {}"?
>
> Thanks in advance!
>
> ------------------------------------------------------------------------------
> PS: Check out my D-IDE at http://www.alexanderbothe.com/?id=27
|
Copyright © 1999-2021 by the D Language Foundation