Undo virtual

This is a discussion on Undo virtual within the C++ Programming forums, part of the General Programming Boards category; I want to call an overrided virtual in a base class from my derived class, how? Below is my attempt. ...

  1. #1
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    583

    Undo virtual

    I want to call an overrided virtual in a base class from my derived class, how? Below is my attempt.
    Code:
    #include <iostream>
    
    using namespace std;
    
    class Base
    {
        public:
        virtual void Print()
        {
            cout << "Base" << endl;
        }
    };
    
    class Derived : public Base
    {
        public:
        virtual void Print()
        {
            cout << "Derived" << endl;
        }
    
        void Base_Print()
        {
            ((Base*)this)->Print();
        }
    };
    
    int main()
    {
        class Derived d;
        d.Base_Print();
        return 0;
    }

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    6,829
    All you have to do is call Base::Print(). Nothing else is needed.
    Quote Originally Posted by phantomotap
    Can you write code while blindfolded only with the blind covering your brain? Can you code while brainfolded?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Virtual Box
    By ssharish2005 in forum Tech Board
    Replies: 3
    Last Post: 02-12-2009, 04:08 AM
  2. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  3. Program with Shapes using Virtual Functions
    By goron350 in forum C++ Programming
    Replies: 12
    Last Post: 07-17-2005, 01:42 PM
  4. C++ XML Class
    By edwardtisdale in forum C++ Programming
    Replies: 0
    Last Post: 12-10-2001, 10:14 PM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 01:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21