www.digitalmars.com         C & C++   DMDScript  

D - overloaded module and class functions

reply "Daniel Yokomiso" <daniel_yokomiso yahoo.com.br> writes:
Hi,

    The compiler complains that "function func () does not match argument
types (char)" in the call func(this.value). Shouldn't it call the func(char)
defined in the module instead of trying to apply the func method member? I'm
using dmd 0.48.


int main() {
    printf("%c\r\n", (new A('a')).func());
    return 0;
}
class A {
    private char value;
    this(char c) {
        this.value = c;
    }
    public char func() {
        return func(this.value);
    }
}
char func(char c) {
   return c;
}


    Best regards,
    Daniel Yokomiso.

"The difference between me and the other surrealists is that I'm a
surrealist."
- Dali
Nov 15 2002
next sibling parent "zhang li" <li stands.3322.org> writes:
Usual I will divide the codes to minimum units.
put its in each lines.
that more ease to debug.

li :)


"Daniel Yokomiso" <daniel_yokomiso yahoo.com.br> 写入消息新闻
:ar3nho$1t3u$1 digitaldaemon.com...
 Hi,

     The compiler complains that "function func () does not match argument
 types (char)" in the call func(this.value). Shouldn't it call the

 defined in the module instead of trying to apply the func method member?

 using dmd 0.48.


 int main() {
     printf("%c\r\n", (new A('a')).func());
     return 0;
 }
 class A {
     private char value;
     this(char c) {
         this.value = c;
     }
     public char func() {
         return func(this.value);
     }
 }
 char func(char c) {
    return c;
 }


     Best regards,
     Daniel Yokomiso.

 "The difference between me and the other surrealists is that I'm a
 surrealist."
 - Dali

Nov 15 2002
prev sibling parent "Walter" <walter digitalmars.com> writes:
No, each scope has its own, seperate function overloading. The reason is to
try to avoid the confusion of multiple scopes interfering with each other.
You can write a 'forwarding function', however, to forward a function call
out of scope:

    char func(char c)
    {
        return some_other_scope.func(c);
    }

"Daniel Yokomiso" <daniel_yokomiso yahoo.com.br> wrote in message
news:ar3nho$1t3u$1 digitaldaemon.com...
 Hi,

     The compiler complains that "function func () does not match argument
 types (char)" in the call func(this.value). Shouldn't it call the

 defined in the module instead of trying to apply the func method member?

 using dmd 0.48.


 int main() {
     printf("%c\r\n", (new A('a')).func());
     return 0;
 }
 class A {
     private char value;
     this(char c) {
         this.value = c;
     }
     public char func() {
         return func(this.value);
     }
 }
 char func(char c) {
    return c;
 }


     Best regards,
     Daniel Yokomiso.

 "The difference between me and the other surrealists is that I'm a
 surrealist."
 - Dali

Nov 15 2002