Re: Problem with overloaded functions
From: Dennis Myrén (dennis_at_oslokb.no)
Date: 02/24/05
- Next message: Martin Honnen: "Re: c# assembly access from Java script"
- Previous message: MikeY: "Help 'Check ListView' vs 'Check ListBox'"
- In reply to: Daniel Lidström: "Problem with overloaded functions"
- Next in thread: Bob Powell [MVP]: "Re: Problem with overloaded functions"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 24 Feb 2005 16:42:23 +0100
You should declare the overridable methods in the Point2D
as virtual to make them overridable(or abstract if they must be overridden,
and have no default inplementation).
Then use keyword override in the derived class Point3D,
like this:
public class Point3D : Point2D
{
public override void WriteXml(XmlWriter w)
{
// TODO
}
public override XmlSchema GetSchema()
{
// TODO
return null;
}
public void ReadXml2(XmlReader reader)
{
// TODO
}
}
public class Point2D : IXmlSerializable
{
public virtual void WriteXml(XmlWriter w)
{
}
public virtual XmlSchema GetSchema()
{
return null;
}
public void ReadXml(XmlReader reader)
{
}
}
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Daniel Lidström" <someone@microsoft.com> wrote in message
news:6uo4qesnyk5i.gguhokpmtabp$.dlg@40tude.net...
> Hello,
>
> I get warnings when trying to compile this code:
>
> public class Point3D : Point2D
> {
> public void WriteXml(XmlWriter w)
> {
> // TODO
> }
>
> public XmlSchema GetSchema()
> {
> // TODO
> return null;
> }
>
> public void ReadXml2(XmlReader reader)
> {
> // TODO
> }
> }
>
> public class Point2D : IXmlSerializable
> {
> public void WriteXml(XmlWriter w)
> {
> }
>
> public XmlSchema GetSchema()
> {
> return null;
> }
>
> public void ReadXml(XmlReader reader)
> {
> }
> }
>
> class1.cs(23,15): warning CS0108: The keyword new is required on
> 'Point3D.WriteXml(System.Xml.XmlWriter)' because it hides inherited member
> 'Point2D.WriteXml(System.Xml.XmlWriter)'
> class1.cs(65,15): (Related location)
> class1.cs(32,20): warning CS0108: The keyword new is required on
> 'Point3D.GetSchema()' because it hides inherited member
> 'Point2D.GetSchema()'
> class1.cs(73,20): (Related location)
> class1.cs(38,15): warning CS0108: The keyword new is required on
> 'Point3D.ReadXml(System.Xml.XmlReader)' because it hides inherited member
> 'Point2D.ReadXml(System.Xml.XmlReader)'
> class1.cs(79,15): (Related location)
>
> Why can I not overload functions this way? Point3D.WriteXml is not called
> when I think it should be. Can someone explain this to a C++ programmer?
> Thanks!
>
> --
> Daniel
> A: Because it messes up the order in which people normally read text.
> Q: Why is top-posting such a bad thing?
> A: Top-posting.
> Q: What is the most annoying thing on usenet and in e-mail?
- Next message: Martin Honnen: "Re: c# assembly access from Java script"
- Previous message: MikeY: "Help 'Check ListView' vs 'Check ListBox'"
- In reply to: Daniel Lidström: "Problem with overloaded functions"
- Next in thread: Bob Powell [MVP]: "Re: Problem with overloaded functions"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|