polymorphism in simple classes
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: polymorphism in simple classes

Threaded View

  1. #1
    Join Date
    Jun 2012
    Posts
    38

    polymorphism in simple classes

    In this thread I have proved that

    PHP Code:
    class A
    {
    public:
        static 
    void func(){std::cout<<"A\n";}
    };

    class 
    B:public A
    {
    public:
        
    virtual void func(){A::func();}
    };

    class 
    C:public B
    {
    public:    
        
    virtual void funx(){func();}
    };

    class 
    D:public C
    {
    public:
        
    virtual void func(){std::cout<<"CC\n";}
        
    void Call(){funx();}
    };

    int _tmain(int argc_TCHARargv[])
    {
        
    D b;
        
    b.Call();
        return 
    0;

    the D::func is not polymophically called in the client code and in C++ I can eliminate "virtual" key, as it is indifferent, but in managed C++
    PHP Code:
    ref class A
    {
    public:
        static 
    void func(){Console::WriteLine("A");}
    };

    ref class B:public A
    {
    public:
        
    virtual void func(){A::func();}
    };

    ref class C:public B
    {
    public:    
        
    virtual void funx(){func();}
    };

    ref class D:public C
    {
    public:
        
    virtual void func() override {Console::WriteLine("CC");}
        
    void Call(){funx();}
    }; 
    I can't eliminate the virtual key in the D class. I wonder is this D::func polymorphically created once called ? Thank you
    Last edited by terminalXXX; June 20th, 2013 at 10:22 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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center