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 Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kris schrieb am Fri, 8 Apr 2005 22:33:28 -0700:
 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.
Added to DStress as http://dstress.kuehne.cn/run/overload_19.d http://dstress.kuehne.cn/run/overload_20.d http://dstress.kuehne.cn/run/overload_21.d http://dstress.kuehne.cn/run/overload_22.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCV3Ox3w+/yD4P9tIRArn7AJ9jUa9RLXf4pmQfgXErhi+me/+hUgCgpTBD 4YwFyD9Kgv8m9ID5YtTnngI= =vQse -----END PGP SIGNATURE-----
Apr 08 2005
prev sibling 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
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
prev sibling parent reply 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
parent Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

xs0 schrieb am Thu, 12 May 2005 16:00:38 +0200:
 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);
      }
 }
Added to DStress as http://dstress.kuehne.cn/run/s/static_30_A.d http://dstress.kuehne.cn/run/s/static_30_B.d http://dstress.kuehne.cn/run/s/static_30_C.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFChZ5w3w+/yD4P9tIRAvkRAJ9Hw40Dj9WUNtghecYNnRPhSb5BtgCgzsu9 pQJ7k0BrkFgiOJX+FHFcduI= =DZsx -----END PGP SIGNATURE-----
May 13 2005