digitalmars.D.learn - Why does this work?
- Joey Peters (17/17) Mar 21 2005 Why does:
- Regan Heath (14/31) Mar 21 2005 At the moment it only works for arrays. int[],char[],etc
Why does: int myLength(char[] test) { return test.length; } char[] test = "hello"; test.myLength(); work, and not: class foo { char[] d; this(char[] t) { d = t; } } viod myPrint(foo test) { printf("%.*s", test.d); } foo test = new test("hello"); test.myPrint(); ? Is it just predefined for all the basic types, just arrays, or what?
Mar 21 2005
On Mon, 21 Mar 2005 11:42:00 +0100, Joey Peters <squirrel nidhogg.com> wrote:Why does: int myLength(char[] test) { return test.length; } char[] test = "hello"; test.myLength(); work, and not: class foo { char[] d; this(char[] t) { d = t; } } viod myPrint(foo test) { printf("%.*s", test.d); } foo test = new test("hello"); test.myPrint(); ? Is it just predefined for all the basic types, just arrays, or what?At the moment it only works for arrays. int[],char[],etc I would like to see it work for basic types also. int,long,float,etc. Perhaps even for struct/union/class, though it would need to detect collissions eg. class A { void foo(){} } void foo(A a) {} A a = new A(); a.foo(); //which one, the member or the stand-alone function? Regan
Mar 21 2005