Closed Thread
Results 1 to 2 of 2

Thread: Virtual Functions ????

  1. #1
    Patrick is offline Programmer
    Join Date
    Sep 2007
    Posts
    101
    Rep Power
    0

    Virtual Functions ????

    Please explain the concept of virtual functions using a simple example and how its working is different from that of normal functions . Is there any special syntax for declaring these functions except the use of keyword Virtual

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    v0id is offline Retired
    Join Date
    Apr 2007
    Posts
    2,937
    Blog Entries
    3
    Rep Power
    42
    Code:
    // Making an interface for deriving classes
    class Base
    {
        public:
            // Deriving classes have to override the following function
            virtual void foo() = 0;
    };
    
    // A class deriving from the base class
    class Derived
        : public Base
    {
        public:
            // Overrides and implements the function now
            void foo() { /* do something... */ }
    };
    
    // ...
    
    Derived *dObj = new Derived;
    // Use it in some way
    delete dObj;

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 02-06-2011, 01:37 PM
  2. SQL Functions - Math Functions
    By chili5 in forum Tutorials
    Replies: 6
    Last Post: 09-02-2009, 02:11 PM
  3. Virtual Functions and Polymorphism
    By ZekeDragon in forum C Tutorials
    Replies: 5
    Last Post: 08-23-2009, 11:51 PM
  4. Subclasses & virtual functions
    By RobotGymnast in forum C and C++
    Replies: 7
    Last Post: 12-13-2008, 06:54 PM
  5. virtual functions
    By Chinmoy in forum C Tutorials
    Replies: 0
    Last Post: 03-17-2008, 09:03 PM

Tags for this Thread

Bookmarks

Posting Permissions

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