www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - static and non-static methods with same name

reply "Kris" <fu bar.com> writes:
class Foo
{
        void init (int x) {}

       static void init (long y) {}
}

Given the above, an attempt to call either one causes a compile error;
changing one of the method names resolves the conflict.
Apr 08 2005
next sibling parent reply Sean Kelly <sean f4.ca> writes:
In article <d37pf8$17b3$2 digitaldaemon.com>, Kris says...
class Foo
{
        void init (int x) {}

       static void init (long y) {}
}

Given the above, an attempt to call either one causes a compile error;
changing one of the method names resolves the conflict.

FWIW, I can't reproduce this with DMD .120. Sean
Apr 09 2005
next sibling parent "Kris" <fu bar.com> writes:
Thanks, Sean. Was this one fixed in v119? I see something similar noted
there.

(couldn't use that version, given the "base class forward reference" issue,
and couldn't download v120)


"Sean Kelly" <sean f4.ca> wrote in message
news:d392i3$164f$1 digitaldaemon.com...
 In article <d37pf8$17b3$2 digitaldaemon.com>, Kris says...
class Foo
{
        void init (int x) {}

       static void init (long y) {}
}

Given the above, an attempt to call either one causes a compile error;
changing one of the method names resolves the conflict.

FWIW, I can't reproduce this with DMD .120. Sean

Apr 09 2005
prev sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Sean Kelly wrote:
 In article <d37pf8$17b3$2 digitaldaemon.com>, Kris says...
 
class Foo
{
       void init (int x) {}

      static void init (long y) {}
}

Given the above, an attempt to call either one causes a compile error;
changing one of the method names resolves the conflict.

FWIW, I can't reproduce this with DMD .120.

The fix of this bug _was_ documented in the changelog. But it's vanished. And using "init" as a member name is silly - it eclipses the built-in .init property, screwing up generic programming. I don't know why Walter didn't make this illegal. Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Apr 12 2005
prev sibling parent reply "Walter" <newshound digitalmars.com> writes:
"Kris" <fu bar.com> wrote in message news:d37pf8$17b3$2 digitaldaemon.com...
 class Foo
 {
         void init (int x) {}

        static void init (long y) {}
 }

 Given the above, an attempt to call either one causes a compile error;
 changing one of the method names resolves the conflict.

The following compiles and runs fine: class Foo { int init (int x) { return 1; } static int init (long y) { return 2; } } void main() { Foo f = new Foo(); int i; i = f.init(1); assert(i == 1); i = f.init(1L); assert(i == 2); }
Apr 09 2005
next sibling parent "Kris" <fu bar.com> writes:
Thanks; the issue was resolved via the fixes in v119 (which couldn't be used
due to that "base-class forward-ref" bug).


"Walter" <newshound digitalmars.com> wrote in message
news:d399dv$1jp6$1 digitaldaemon.com...
 "Kris" <fu bar.com> wrote in message

 class Foo
 {
         void init (int x) {}

        static void init (long y) {}
 }

 Given the above, an attempt to call either one causes a compile error;
 changing one of the method names resolves the conflict.

The following compiles and runs fine: class Foo { int init (int x) { return 1; } static int init (long y) { return 2; } } void main() { Foo f = new Foo(); int i; i = f.init(1); assert(i == 1); i = f.init(1L); assert(i == 2); }

Apr 09 2005
prev sibling parent xs0 <xs0 xs0.com> writes:
I get this with 0.123:

test.d(13): 'this' is required, but test.Foo is not a base class of Bar
test.d(13): class test.Bar member hash is not accessible

Both of which don't make sense to me..

module test;

public class Foo
{
     public int hash() {}
     public static int hash(double val) {}
}

public class Bar
{
     public int hash()
     {
         return Foo.hash(1);
     }
}


xs0

PS: it happens if there is code in funcs, too


Walter wrote:
 "Kris" <fu bar.com> wrote in message news:d37pf8$17b3$2 digitaldaemon.com...
 
class Foo
{
        void init (int x) {}

       static void init (long y) {}
}

Given the above, an attempt to call either one causes a compile error;
changing one of the method names resolves the conflict.

The following compiles and runs fine: class Foo { int init (int x) { return 1; } static int init (long y) { return 2; } } void main() { Foo f = new Foo(); int i; i = f.init(1); assert(i == 1); i = f.init(1L); assert(i == 2); }

May 12 2005