Compilation depends on class methods order

kdmult kdmult at ya.ru
Thu Dec 19 23:03:15 PST 2013


Hi,

Why compilation depends on order of method declarations?

The following test case does not compile.

However, if we change the order of the 'read' methods in class 
InputStream below then  compilation will not fail.

Is it a bug?

---
module test;

import std.traits : isBasicType;
import std.typetuple : TypeTuple;

class InputStream {

     long read( ubyte* bytes, long len )
     {
         return 0;
     }

     void read(T)( ref T val ) if (isBasicType!T)
     {
         read(cast(ubyte*)&val, cast(long)val.sizeof);
     }

}

void main()
{
     auto input = new InputStream;

     foreach (T; TypeTuple!(long, int, short, byte))
     {
         T v;
         input.read(v);
     }
}
---

Thanks.


More information about the Digitalmars-d-learn mailing list