www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - typedef members inaccessible

reply Vathix <chris dprogramming.com> writes:
struct Foo
{
    void stuff() { }
}
typedef Foo Bar;
int main()
{
    Bar b;
    b.stuff(); // here
    return 0;
}


DMD 0.137 output:
    test.d(9): this for stuff needs to be type Foo not type Bar


Was this intended? If so, what is the reason? Shouldn't the type  
implicitly convert to its base to find the member?
Oct 27 2005
parent Derek Parnell <derek psych.ward> writes:
On Fri, 28 Oct 2005 02:31:25 -0400, Vathix wrote:

 struct Foo
 {
     void stuff() { }
 }
 typedef Foo Bar;
 int main()
 {
     Bar b;
     b.stuff(); // here
     return 0;
 }
 
 DMD 0.137 output:
     test.d(9): this for stuff needs to be type Foo not type Bar
 
 Was this intended? If so, what is the reason? Shouldn't the type  
 implicitly convert to its base to find the member?

I must admit that this looks odd ... struct Foo { void stuff() { } } typedef Foo Bar; int main() { Bar b; (cast(Foo)b).stuff(); // now it works. return 0; } Also, instead of typedef, alias makes it compile, but I guess that's not your point. -- Derek (skype: derek.j.parnell) Melbourne, Australia 28/10/2005 4:51:21 PM
Oct 27 2005