www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 419] New: Anonymous classes are not working.

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=419

           Summary: Anonymous classes are not working.
           Product: D
           Version: 0.169
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: benoit tionex.de


interface I {
    void get( char[] s );
}
class C{
    void init(){
        I i = new class() I {
            void get( char[] s ){
                func();  // line 8
            }
        };
    }
    void func( ){ }
}
void main(){
}

an.d(8): this for func needs to be type C not type void*
See also: http://www.digitalmars.com/d/class.html#anonymous

Doing that line
        I i = new class() { // without the "I"
gives this nice message:
an.d(8): this for func needs to be type C not type void*
an.d(6): cannot implicitly convert expression ((class __anonclass1 : Object
{
    void get(char[] s)
{
assert(this,"null this");
((this.this).func)();
}
    void* this;
}
) , new __anonclass1) of type an.C.init.__anonclass1 to an.I


-- 
Oct 09 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=419


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED





Fixed DMD 0.170


-- 
Oct 18 2006
prev sibling parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

d-bugmail puremagic.com schrieb am 2006-10-09:
 http://d.puremagic.com/issues/show_bug.cgi?id=419
 interface I {
     void get( char[] s );
 }
 class C{
     void init(){
         I i = new class() I {
             void get( char[] s ){
                 func();  // line 8
             }
         };
     }
     void func( ){ }
 }
 void main(){
 }

 an.d(8): this for func needs to be type C not type void*
<snip> Added to DStress as http://dstress.kuehne.cn/run/t/this_13_A.d http://dstress.kuehne.cn/run/t/this_13_B.d http://dstress.kuehne.cn/run/t/this_13_C.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFFOilNLK5blCcjpWoRAlSHAJ9JX/gND++RZtDGNNHFr19Cspo89ACfUAN1 wihuTFjMM92bs4sN6xviX50= =VZf2 -----END PGP SIGNATURE-----
Oct 21 2006