D2 Pointer confusion
Ellery Newcomer
ellery-newcomer at utulsa.edu
Tue Sep 1 14:01:21 PDT 2009
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
More information about the Digitalmars-d-learn
mailing list