Showing posts with label Concept of Overloading and Overiding functions. Show all posts
Showing posts with label Concept of Overloading and Overiding functions. Show all posts

Friday, 27 January 2012

How to Use Virtual Function in C++

     #include<iostream.h>
      class Window // Base class for C++ virtual function example
      {
         public:
      virtual     void Create(int a) // virtual function for C++ virtual function example
             {
                    cout <<"Base class Window"<<a;
             }
      };

      class CommandButton : public Window
      {
         public:
             void Create()
             {
                  cout<<"Derived class Command Button - Overridden C++ virtual function";
             }

             void Create(int a, int b)
             {
                  cout<<"Derived class Command Button - a and b"<<a<<b;
             }

      };

      void main()
      {
            Window  *x, *y;

         // x = new Window();
         // x->Create();


            //y = new CommandButton();
            //y->Create(10);

            CommandButton *cb;
            cb=new CommandButton();
            cb->Create();
            cb->Create(140,2);
            }