digitalmars.D.learn - D2 Pointer confusion
- A Bothe (31/31) Aug 30 2009 Hey guys,
- Ellery Newcomer (21/57) Sep 01 2009 Umm.. A shot in the dark?
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
Aug 30 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
Sep 01 2009








Ellery Newcomer <ellery-newcomer utulsa.edu>