I am cleaning out warnings. One wasn't really clear, despite quite some explanation in https://www.xsharp.eu/help/xs0108.html (PS there's a typo Or, you van simply enable which should be 'can'
I get this warning:
Warning XS0108 MySubclass_SomeMethod hides inherited member MyBaseClass_SomeMethod Use the new keyword if hiding was intended.
Indeed this is like in my VO program, a method with the same name as the one in the base class. This is also even called, with super. I don't have All methods are virtual checked. I could probably do that, without any further issues, but I wonder:
1 The explanation in the help suggests stat (now) I've got a 'completely new method'. But despite the warning, the super: call is executed perfectly, like in VO.
2 To be 'compliant', I added VIRTUAL in front of the method name as suggested in the help. That compiles, so I assume I put it in the right spot, but the warning remains.
Either I miss something, or it doesn't work as the warning suggested and the warning (hence) needn't be there, I'd say?
Dick
Warning XS0108 x_Mth hides inherited member y_Mth Use the new keyword if hiding was intended.
Re: Warning XS0108 x_Mth hides inherited member y_Mth Use the new keyword if hiding was intended.
Hi Dick,
SUPER works, because you explicitly tell the compiler to call the base method. But the child method does not override the parent one, I think it's best to explain with a sample, see the inline comments below. If you define the methods as virtual, then the child method will be called in all cases:
SUPER works, because you explicitly tell the compiler to call the base method. But the child method does not override the parent one, I think it's best to explain with a sample, see the inline comments below. If you define the methods as virtual, then the child method will be called in all cases:
Code: Select all
CLASS Parent
METHOD NonVirtual() AS VOID
? "parent called"
METHOD Test() AS VOID
SELF:NonVirtual()
END CLASS
CLASS Child INHERIT Parent
METHOD NonVirtual() AS VOID
? "child called"
END CLASS
FUNCTION Start() AS VOID
LOCAL parent AS Parent
LOCAL child AS Child
parent := Child{}
child := Child{} // note that both objects represent the child class
child:NonVirtual() // child, because local is typed AS Child, so the compiler calls the child method directly
parent:NonVirtual() // parent, because the compiler calls the parent method and the child method does not override the child one
parent:Test() // parent, same as above
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu
Re: Warning XS0108 x_Mth hides inherited member y_Mth Use the new keyword if hiding was intended.
Hello Chris,
You write " But the child method does not override the parent one". But the way I see it, it does work exactly as in VO. The child method is called from the child class's menu, it calls the super method as well. Basically the only difference with VO is that I now get a warning which (like the one about the -possibly uninitialized) is probably technically correct but there's, as far as I understand, no way to get rid of the warning except hiding this specific warning, correct?
That doesn't really bother me, but my aim was to get rid of all or most warnings so only the ones which would be useful would remain.
Dick
You write " But the child method does not override the parent one". But the way I see it, it does work exactly as in VO. The child method is called from the child class's menu, it calls the super method as well. Basically the only difference with VO is that I now get a warning which (like the one about the -possibly uninitialized) is probably technically correct but there's, as far as I understand, no way to get rid of the warning except hiding this specific warning, correct?
That doesn't really bother me, but my aim was to get rid of all or most warnings so only the ones which would be useful would remain.
Dick
Re: Warning XS0108 x_Mth hides inherited member y_Mth Use the new keyword if hiding was intended.
Hi Dick,
If you compile and run the code I posted also in VO, you will see that it does not work exactly as in VO, if you do not make the methods virtual (in VO, all methods are always virtual).
If you compile and run the code I posted also in VO, you will see that it does not work exactly as in VO, if you do not make the methods virtual (in VO, all methods are always virtual).
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu
Re: Warning XS0108 x_Mth hides inherited member y_Mth Use the new keyword if hiding was intended.
Hello Chris,
I understand what you mean (I hope): although you assign parent := Child{} to a local of class Parent, it will still call the method from the parent class and in VO it won't.
But the example is a bit academic. I have a method x of class parent and the same method x of class child and when I call the method x of child this way assigned, it will run the method of the class child and can still run the method of the class parent with super. That is not different than in VO and I think this is more a 'real world method"?
Also, adding VIRTUAL in front of the method did not get rid of the warning. Shouldn't it?
Dick
I understand what you mean (I hope): although you assign parent := Child{} to a local of class Parent, it will still call the method from the parent class and in VO it won't.
But the example is a bit academic. I have a method x of class parent and the same method x of class child and when I call the method x of child this way assigned, it will run the method of the class child and can still run the method of the class parent with super. That is not different than in VO and I think this is more a 'real world method"?
Also, adding VIRTUAL in front of the method did not get rid of the warning. Shouldn't it?
Dick
Re: Warning XS0108 x_Mth hides inherited member y_Mth Use the new keyword if hiding was intended.
Dick,
Please create a small example, and include the compiler options that you're using.
If you're using XIDE you can save the reponse file from the Application Menu, that contains the command line generated by XIDE.
In VS you can include the xsproj file.
Robert
Please create a small example, and include the compiler options that you're using.
If you're using XIDE you can save the reponse file from the Application Menu, that contains the command line generated by XIDE.
In VS you can include the xsproj file.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
Re: Warning XS0108 x_Mth hides inherited member y_Mth Use the new keyword if hiding was intended.
Hi Dick,
I think you made the child method VIRTUAL, not the parent one. It's the parent method that you need to make VIRTUAL, which means that it can be overridden by a child method.
I think you made the child method VIRTUAL, not the parent one. It's the parent method that you need to make VIRTUAL, which means that it can be overridden by a child method.
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu
Re: Warning XS0108 x_Mth hides inherited member y_Mth Use the new keyword if hiding was intended.
Hello Chris,
I think you made the child method VIRTUAL, not the parent one. It's the parent method that you need to make VIRTUAL, which means that it can be overridden by a child method.
Yes sir! That was it, as so often you were able to follow someone's flaw logic to solve a question or problem - in this case one of mine.
I added VIRTUAL in front of the parent class' method and the warnings are gone.
Now It still works as it did in VO - but with the right conventions.
Have a nice Christmas!
Dick
I think you made the child method VIRTUAL, not the parent one. It's the parent method that you need to make VIRTUAL, which means that it can be overridden by a child method.
Yes sir! That was it, as so often you were able to follow someone's flaw logic to solve a question or problem - in this case one of mine.
I added VIRTUAL in front of the parent class' method and the warnings are gone.
Now It still works as it did in VO - but with the right conventions.
Have a nice Christmas!
Dick
Re: Warning XS0108 x_Mth hides inherited member y_Mth Use the new keyword if hiding was intended.
Merry Christmas to you, too, Dick!
And to everybody else of course..
And to everybody else of course..
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu