CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Threaded View

  1. #1
    Join Date
    Mar 2009
    Posts
    17

    Question simple override question

    hello,

    OK i need a little help,

    i want to override a funtion from a parent class, but i can seem to get it to work,

    so i have a layout the same as below, i want to override the Z function from class A in class B.
    when i use this layout below it still calls the Z function from A rather than B, i am creating the object from B so from my understanding it should be overwrote...

    can anyone help me out with this?

    thanks
    Philly

    Class A Header:
    Code:
    #pragma once
    
    class A
    {
    private:
        void Y();
    protected:
        virtual void Z();
    };
    class A Source:
    Code:
    #include "stdafx.h"
    #include "A.h"
    
    void A::Y()
    {
        this->Z();
    }
    
    void A::Z()
    {
        // want to override this in class B;
    }
    Class B Header
    Code:
    #pragma once
    #include "A.h"
    
    class B : A
    {
    protected:
        void Z();
    };
    Class B Source:
    Code:
    #include "stdafx.h"
    #include "B.h"
    
    void B::Z()
    {
        // Do Somthing Here!
    }
    Last edited by StaticPhilly; March 12th, 2009 at 07:28 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured