www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - D Inheritance bug - test.d

reply D Trebbien <D_member pathlink.com> writes:
class A
{
void test(int val)
{
}
}

class B : A
{
void test()
{
}
}

int main(char[][] args)
{
B b=new B();
b.test(6);

return 0;
}

(this code is attached for reference)

test.d(18): function test () does not match argument types (int)
test.d(18): Error: expected 0 arguments, not 1


begin 0644 test.d




`
end
Jan 07 2005
next sibling parent John Reimer <brk_6502 yahoo.com> writes:
D Trebbien wrote:
 class A
 {
 void test(int val)
 {
 }
 }
 
 class B : A
 {
 void test()
 {
 }
 }
 
 int main(char[][] args)
 {
 B b=new B();
 b.test(6);
 
 return 0;
 }
 
 (this code is attached for reference)
 
 test.d(18): function test () does not match argument types (int)
 test.d(18): Error: expected 0 arguments, not 1
 
 
This isn't a bug. This is the way D name resolution works. If you want to be able to use class A's test() from a B object, you'll have to define an alias to it that brings it into B's namespace. You might like to do a search of this newsgroup for a more detailed explanation of why D does name resolution this way. A fair bit of discussion about this has already taken place. Later, John
Jan 07 2005
prev sibling next sibling parent reply Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Added to DStress as:
http://dstress.kuehne.cn/run/run/overload_12.d
http://dstress.kuehne.cn/run/run/overload_13.d

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFB3wDh3w+/yD4P9tIRAnxdAJ40vwfHWMHBhN/csXXqMUlcPd1TggCgkknb
zgVBfFPug071TTrk5SlLY8c=
=6HHY
-----END PGP SIGNATURE-----
Jan 07 2005
parent reply Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

 Added to DStress as:
 http://dstress.kuehne.cn/run/run/overload_12.d
 http://dstress.kuehne.cn/run/run/overload_13.d
Arg... shouldn't switch languages that often ... http://dstress.kuehne.cn/nocompile/overload_12.d http://dstress.kuehne.cn/nocompile/overload_13.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFB3wPW3w+/yD4P9tIRAp6GAJ9mtlp4QwXfJ4q+G0kbL8GDhazNqACgyXUc Bx3GLWkPGMkgr68d2HlOFn0= =mipW -----END PGP SIGNATURE-----
Jan 07 2005
parent reply John Reimer <brk_6502 yahoo.com> writes:
Thomas Kuehne wrote:
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
 
Added to DStress as:
http://dstress.kuehne.cn/run/run/overload_12.d
http://dstress.kuehne.cn/run/run/overload_13.d
Arg... shouldn't switch languages that often ... http://dstress.kuehne.cn/nocompile/overload_12.d http://dstress.kuehne.cn/nocompile/overload_13.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFB3wPW3w+/yD4P9tIRAp6GAJ9mtlp4QwXfJ4q+G0kbL8GDhazNqACgyXUc Bx3GLWkPGMkgr68d2HlOFn0= =mipW -----END PGP SIGNATURE-----
I know the example looks like an error in method overloading, but doesn't overloading specifically refer to use of methods with the same name (with different parameters) within the same class. D doesn't automatically bring superclass methods of the same name into the subclass's name space (or whatever you call it) by design. Since this is part of D's design, this is not a issue of incorrect overloading (though, I'm sure, some people wish it were). I remember this D "feature" being haggled over in detail. Some OOP programmer's found the D mechanism distasteful, especially those that came from a Java background. But, I believe Walter has indicated ferverently that this is the way D was designed and the only sane way for the language to work. Correct me if I'm wrong. Later, John
Jan 07 2005
parent "Simon Buchan" <not a.valid.address.com> writes:
On Fri, 07 Jan 2005 16:20:03 -0800, John Reimer <brk_6502 yahoo.com> wrote:

 Thomas Kuehne wrote:
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1


 Added to DStress as:
 http://dstress.kuehne.cn/run/run/overload_12.d
 http://dstress.kuehne.cn/run/run/overload_13.d
Arg... shouldn't switch languages that often ... http://dstress.kuehne.cn/nocompile/overload_12.d http://dstress.kuehne.cn/nocompile/overload_13.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFB3wPW3w+/yD4P9tIRAp6GAJ9mtlp4QwXfJ4q+G0kbL8GDhazNqACgyXUc Bx3GLWkPGMkgr68d2HlOFn0= =mipW -----END PGP SIGNATURE-----
I know the example looks like an error in method overloading, but doesn't overloading specifically refer to use of methods with the same name (with different parameters) within the same class. D doesn't automatically bring superclass methods of the same name into the subclass's name space (or whatever you call it) by design. Since this is part of D's design, this is not a issue of incorrect overloading (though, I'm sure, some people wish it were). I remember this D "feature" being haggled over in detail. Some OOP programmer's found the D mechanism distasteful, especially those that came from a Java background. But, I believe Walter has indicated ferverently that this is the way D was designed and the only sane way for the language to work. Correct me if I'm wrong. Later, John
Hmm.... Not wanting to open a can of worms here, but I can see both sides of this, clear and clean syntax, or in-your-face lists of all overloaded fuctions, so you KNOW what could be called. However, with no implicit casting of classes, and the fact that non-overloaded functions are still brought in, I would have to go with not requiring aliasing. Huge volumes of aliases for overloading probably means you're doing something wrong, in any case. Could this just be the default private access? I think that probably was just cut for space. -- "Yes, the american troops have advanced further. This will only make it easier for us to defeat them" - Iraqi Information Minister Muhammed Saeed al-Sahaf
Jan 07 2005
prev sibling parent reply David L. Davis <SpottedTiger yahoo.com> writes:
In article <crmrb6$2slf$1 digitaldaemon.com>, D Trebbien says...
class A
{
void test(int val)
{
}
}

class B : A
{
void test()
{
}
}

int main(char[][] args)
{
B b=new B();
b.test(6);

return 0;
}

(this code is attached for reference)

test.d(18): function test () does not match argument types (int)
test.d(18): Error: expected 0 arguments, not 1


begin 0644 test.d




`
end
D Trebbien : Below may be a way to do what you what without an alias. Output: C:\dmd>bin\dmd class_inhert2.d C:\dmd\bin\..\..\dm\bin\link.exe class_inhert2,,,user32+kernel32/noi; C:\dmd>class_inhert2 A.test( in int iVal="6" ) Called. B.test() Called. C:\dmd> David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"
Jan 08 2005
next sibling parent reply "Simon Buchan" <buchan.home ihug.co.nz> writes:
On Sun, 9 Jan 2005 01:47:42 +0000 (UTC), David L. Davis  
<SpottedTiger yahoo.com> wrote:

 In article <crmrb6$2slf$1 digitaldaemon.com>, D Trebbien says...
 class A
 {
 void test(int val)
 {
 }
 }

 class B : A
 {
/* added */ alias void super.test(int) void test(int); // Is this the syntax?
 void test()
 {
 }
 }

 int main(char[][] args)
 {
 B b=new B();
 b.test(6);

 return 0;
 }
<snip>


































<snip> The cure is worse than the disease... -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jan 14 2005
parent David L. Davis <SpottedTiger yahoo.com> writes:
In article <opskk2ado1stcuho simon>, Simon Buchan says...
The cure is worse than the disease...
Simon Buchan: :P Please, feel free to cough up better cure besides the alias approach, which of course adds it's very own set of problems. Thus far, you haven't added anything positive to this topic...maybe it's time you did. :)) ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"
Jan 14 2005
prev sibling parent "D. Trebbien" <dtrebbien gmail.com> writes:
David L. Davis wrote:
 In article <crmrb6$2slf$1 digitaldaemon.com>, D Trebbien says...
 
class A
{
void test(int val)
{
}
}

class B : A
{
void test()
{
}
}

int main(char[][] args)
{
B b=new B();
b.test(6);

return 0;
}

(this code is attached for reference)

test.d(18): function test () does not match argument types (int)
test.d(18): Error: expected 0 arguments, not 1


begin 0644 test.d




`
end
D Trebbien : Below may be a way to do what you what without an alias. Output: C:\dmd>bin\dmd class_inhert2.d C:\dmd\bin\..\..\dm\bin\link.exe class_inhert2,,,user32+kernel32/noi; C:\dmd>class_inhert2 A.test( in int iVal="6" ) Called. B.test() Called. C:\dmd> David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"
This is a great solution (and makes more sense to me in terms of OO design). Thanks David L.
Mar 10 2005