Virtual Function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ritchie
    New Member
    • Nov 2006
    • 9

    Virtual Function

    wap using virtual function.

    also wap using pointers.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    What do you mean by WAP?

    Comment

    • Ritchie
      New Member
      • Nov 2006
      • 9

      #3
      Originally posted by Banfa
      What do you mean by WAP?
      simple , it stands for write a program.

      can u help me out asap,i mean as soon as possible

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Originally posted by Ritchie
        simple , it stands for write a program.
        well normally it stands for Wireless APplication

        Do you know what a virtual function is? Do you know what pointers are?

        What would you like you program to do?

        Comment

        • Ritchie
          New Member
          • Nov 2006
          • 9

          #5
          Originally posted by Banfa
          well normally it stands for Wireless APplication

          Do you know what a virtual function is? Do you know what pointers are?

          What would you like you program to do?
          yes sir,
          i very well know wat pointers nd virtual functions are,but d thing is i havent touched c++ for over 2 yrs. now.so,i'm starting it all over again.

          Comment

          • Velhari
            New Member
            • Sep 2006
            • 46

            #6
            Originally posted by Ritchie
            yes sir,
            i very well know wat pointers nd virtual functions are,but d thing is i havent touched c++ for over 2 yrs. now.so,i'm starting it all over again.
            Hi,
            Virtual Function is simple one.... we used similar method names in base class and subclass means, we propose to use virtual function(Run-time Polymorphism).. ....

            So, c++ determines which function to use at runtime based on the Object pointed by the Base Pointer rather than type of Pointer.

            Here is a simple program for you to understand the concept of Virtual function

            Code:
            #include <iostream.h>
            
            class virtual_example
            {
                  virtual void show()
                  {
                        cout<<"Base Class";
                  }
            }
            class sub extends virtual_example
            {
                 void show()
                 {
                      cout<<"Derived Class";
                 }
            }
            void main()
            {
                     virtual_example *v; //Base Pointer
                     virtual_example start;
                     sub end;
             
                     v=&start;
                     v->show();
             
                     v=&end;
                     v->show();
            }
            With Regards,
            Velmurugan.H

            Comment

            • Ritchie
              New Member
              • Nov 2006
              • 9

              #7
              Originally posted by Velhari
              Hi,
              Virtual Function is simple one.... we used similar method names in base class and subclass means, we propose to use virtual function(Run-time Polymorphism).. ....

              So, c++ determines which function to use at runtime based on the Object pointed by the Base Pointer rather than type of Pointer.

              Here is a simple program for you to understand the concept of Virtual function

              Code:
              #include <iostream.h>
              
              class virtual_example
              {
                    virtual void show()
                    {
                          cout<<"Base Class";
                    }
              }
              class sub extends virtual_example
              {
                   void show()
                   {
                        cout<<"Derived Class";
                   }
              }
              void main()
              {
                       virtual_example *v; //Base Pointer
                       virtual_example start;
                       sub end;
               
                       v=&start;
                       v->show();
               
                       v=&end;
                       v->show();
              }
              With Regards,
              Velmurugan.H

              thnx a lot.

              Comment

              Working...