March 21, 2005 Why does this work? | ||||
---|---|---|---|---|
| ||||
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? |
March 21, 2005 Re: Why does this work? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joey Peters | 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
|
Copyright © 1999-2021 by the D Language Foundation