Re: Problem with overloaded functions

From: Dennis Myrén (dennis_at_oslokb.no)
Date: 02/24/05


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? 


Relevant Pages

  • Re: Requesting tips, comments for an EDT thread-safe game architecture
    ... Use a Window or JWindow and do active rendering. ... synchronize some parts of your code but the more you can avoid that the ... public void myRenderingLoop() { ...
    (comp.lang.java.gui)
  • Requesting tips, comments for an EDT thread-safe game architecture
    ... me wonder whether my general game architecture was thread safe or not. ... public static void mainthrows InterruptedException, ... public void windowActivated{ ...
    (comp.lang.java.gui)
  • Re: JTree not updating after deleting a node in DnD
    ... public void fireTreeStructureChanged(Object source, TreePath path) ... public MyTransferable(final DefaultMutableTreeNode data) { ...
    (comp.lang.java.gui)
  • Re: Wrong overload resolution ?
    ... The "new" keyword prevents Class2.Method1from being an override of Class1.Method1and the rule i mentioned above do not apply. ... So if you have a variable of type Class1 pointing to an instance of Class2, the method of Class1 will be invoked. ... > more interesting if the strongly typed overload is like override public void ...
    (microsoft.public.dotnet.languages.csharp)