digitalmars.D.learn - class x is hidden by y
- Benjamin Thaut (29/29) Oct 06 2010 For the following code in D 2.0 using dmd 2.049:
- Denis Koroskin (5/35) Oct 07 2010 That the case in C++, too. In C++ you would write using foo::Update.
- Benjamin Thaut (3/3) Oct 07 2010 Thanks, that fixes it
- bearophile (8/13) Oct 07 2010 In D classes start with an upper case, and methods with a lower case (an...
- Simen kjaeraas (5/11) Oct 07 2010 Yes, if one is to slavishly follow the rules set out by someone else.
- bearophile (8/10) Oct 07 2010 How many serious Python packages do you see around where methods are nam...
For the following code in D 2.0 using dmd 2.049: import std.stdio; abstract class foo { protected: void WrongType(){ assert(0,"Using wrong type"); } public: void Update(int value){WrongType();} void Update(float value){WrongType();} } class blup : public foo { public override void Update(int value){ writefln("%s",value); } } void main(string[] argv){ foo s = new blup(); s.Update(2); s.Update(2.5f); } When compiling with -w option I get the following warning: test.d(25): Error: class test.blup test.foo.Update(float value) is hidden by blup When compiling without the -w option I get the following runtime error: core.exception.HiddenFuncError: Hidden method called for test.blup So I don't get why void Update(float value) is hidden. I come from C++ so please show me my mistake. Kind Regards Benjamin Thaut
Oct 06 2010
On Thu, 07 Oct 2010 10:43:12 +0400, Benjamin Thaut <code benjamin-thaut.de> wrote:For the following code in D 2.0 using dmd 2.049: import std.stdio; abstract class foo { protected: void WrongType(){ assert(0,"Using wrong type"); } public: void Update(int value){WrongType();} void Update(float value){WrongType();} } class blup : public foo { public override void Update(int value){ writefln("%s",value); } } void main(string[] argv){ foo s = new blup(); s.Update(2); s.Update(2.5f); } When compiling with -w option I get the following warning: test.d(25): Error: class test.blup test.foo.Update(float value) is hidden by blup When compiling without the -w option I get the following runtime error: core.exception.HiddenFuncError: Hidden method called for test.blup So I don't get why void Update(float value) is hidden. I come from C++ so please show me my mistake. Kind Regards Benjamin ThautThat the case in C++, too. In C++ you would write using foo::Update. In D, "alias foo.Update Update". It means, "bring base class' Update method to the current scope".
Oct 07 2010
Thanks, that fixes it Kind Regards Benjamin Thaut
Oct 07 2010
Benjamin Thaut:abstract class foo { protected: void WrongType(){ assert(0,"Using wrong type"); }In D classes start with an upper case, and methods with a lower case (and both generally use camelCase/CamelCase instead of underscores). So the way to write that code is: abstract class Foo { protected: void wrongType() { Bye, bearophile
Oct 07 2010
bearophile <bearophileHUGS lycos.com> wrote:In D classes start with an upper case, and methods with a lower case (and both generally use camelCase/CamelCase instead of underscores). So the way to write that code is: abstract class Foo { protected: void wrongType() {Yes, if one is to slavishly follow the rules set out by someone else. People may have other coding standards in their own homes. -- Simen
Oct 07 2010
Simen kjaeraas:Yes, if one is to slavishly follow the rules set out by someone else. People may have other coding standards in their own homes.How many serious Python packages do you see around where methods are named in lowercase methods, or lowercase class names? The D language doesn't enforce identifiers case conventions, and in the end you are free to do what you like. But you have to push your nose a bit outside your It's good to have basic language-wide style used by the whole community, it simplifies code written by others. Think about using CamelCase in your Python project. Then you download modules from all places from the net, and add them to your Python program (this happens often in Python). If one module uses names_with_underscores, another module uses camelCase, and another module uses alllowercasewithnospaces then at the end your project will are not that stupid, they follow things like the Python PEP8, that says to use class names with an Upper case starting char, methods as lower_case, and so on. Freedom is good, but in this case its price is too much high, it's not worth it. Stick with the naming convention used by each modern language, you will have less problems in integrating code written by other people, and your code will turn up to be better and more readable by the community. Bye, bearophile
Oct 07 2010