Re: Inheritance



I receive an error with the dot also. The error is below

An object reference is required for the nonstatic field, method, or property
'LevelInheritance.Person.Display()'

"Patrice" wrote:

Use . Instead of ::
--
Patrice

"Weste" <Weste@xxxxxxxxxxxxxxxxxxxxxxxxx> a écrit dans le message de news:
F89B1427-159F-4E7D-AB49-E1F2613B06D9@xxxxxxxxxxxxxxxx
I am attempting to learn OOP. The book uses C++ examples. I am trying to
convert the code to C#. C# doesn't like the statement Person::Display();
in
the Student class. How do I need to modify this to work in C#? Thanks
for
your help.

using System;

namespace LevelInheritance
{
public class Person
{
protected int m_ID;
protected string m_First;
protected string m_Last;

public Person()
{

m_ID = 0;
m_First = "\0";
m_Last = "\0";
}

public virtual void Display()
{
Console.WriteLine("ID: " + m_ID +
"\rFirst: " + m_First +
"\rLast: " + m_Last);
}

public void Write(int ID, string First, string Last)
{
m_ID = ID;
m_First = First;
m_Last = Last;
}
}

class Student: Person
{
protected int m_Graduation;

public override void Display()
{
Person::Display();
Console.WriteLine("Graduation: " + m_Graduation);
}


public void Write(int ID, string First, string Last, int Graduation)
{
Write(ID, First, Last);
m_Graduation = Graduation;
}

public Student()
{
m_Graduation = 0;
}
}




.



Relevant Pages

  • Re: Inheritance
    ... protected string m_First; ... public void Write ... class Student: Person ... protected int m_Graduation; ...
    (microsoft.public.dotnet.general)
  • Re: Is there a limit to the size or complexity of JPanels paintComponent method?
    ... double actualnorthextent, actualsouthextent, actualwestextent, ... public void movemapdown() ... public double convertstringcoordinatetodouble(String coord) ... return screencoords; ...
    (comp.lang.java.gui)
  • Re: Is there a limit to the size or complexity of JPanels paintComponent method?
    ... double actualnorthextent, actualsouthextent, actualwestextent, ... public void movemapdown() ... public double convertstringcoordinatetodouble(String coord) ... return screencoords; ...
    (comp.lang.java.gui)
  • Re: Problem with FTP
    ... > private static Encoding ASCII = Encoding.ASCII; ... > private string message = null; ... > private int port = 21; ... > public void Login() ...
    (microsoft.public.pocketpc.developer)
  • Re: All Menu Navigation
    ... i based the implementation on sample code from http://www.asp.net/CSSAdapters/Menu.aspx, which shows how to create decent HTML for a Menu control bound to a SiteMapDataSource. ... public void RenderBeginTag(HtmlTextWriter writer, string cssClass) ... static public void RemoveProblemTypes ...
    (microsoft.public.dotnet.framework.aspnet)