Overriding class methods

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vasileios Zografos

    #1

    Overriding class methods

    Hi, I am trying to override a class method from a child class like the
    following:


    class ParentClass
    {
    public:
    ParentClass();
    virtual ~ParentClass();
    virtual double someMethod (int)=0;
    }


    ParentClass::Pa rentClass()
    {
    someMethod(1);
    }

    class childClass::pub lic ParentClass
    {
    public:
    childClass(): ParentClass(){; }
    double someMethod(int) ;
    }

    double childClass::som eMethod(int num)
    {
    //do something meaningfull here
    return 0;
    }


    int main()
    {
    childClass cld();
    return 0;
    }


    now, this program will crash because someMethod is called from the
    ParentClass constructor.

    If someMethod is called outside, e.g.

    ParentClass::Pa rentClass()
    {

    }

    and

    int main()
    {
    childClass cld();
    cld.someMethod( );
    return 0;
    }

    it will work fine.
    However, I want to be able to call the overriden method someMethod()
    from the constructor. Is there a way around this problem?

    Thank you
    Vasileios

    --
    Posted via a free Usenet account from http://www.teranews.com

  • Daniel T.

    #2
    Re: Overriding class methods

    Vasileios Zografos <noone@nowhere. netwrote:
    I want to be able to call the overriden method someMethod()
    from the constructor. Is there a way around this problem?

    Comment

    • Vasileios Zografos

      #3
      Re: Overriding class methods

      Daniel T. wrote:
      Vasileios Zografos <noone@nowhere. netwrote:
      >
      >I want to be able to call the overriden method someMethod()
      >from the constructor. Is there a way around this problem?
      >
      http://www.parashift.com/c++-faq-lit....html#faq-23.5
      ok got it ;)

      --
      Posted via a free Usenet account from http://www.teranews.com

      Comment

      Working...