C++
  Home arrow C++ arrow Overview of Virtual Functions
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C++

Overview of Virtual Functions
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-06-15

    Table of Contents:
  • Overview of Virtual Functions
  • Abstract class
  • Virtual versus Pure Virtual
  • Virtual Deconstructor
  • Virtual Deconstructor continued

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Overview of Virtual Functions


    (Page 1 of 5 )

    The word virtual is strange enough on its own. It is defined philosophically as "that which is not real" but contains all of the properties of the real object. However, ultimately something virtual is "fake." Virtual functions are similar in concept, so follow along with me through this article to discover how to use them and when to do so in the C++ language.

    This is the second part of my series covering the polymorphic traits in C++ and object-oriented programming, so if you missed it, make sure to catch up with the first part. This article will pick up from where we took a break last time. Just look for Polymorphism in C++ on this web site; start a search or  simply click on my name to see my profile and get the link from there.

    Now then, if you managed to follow the first part of this article series, welcome back. We learned what the virtual function itself is, and what direct effect it will have on functions where you declare them with the magic keyword in front of them. To put it as simply as possible, from the point of view of working with the functions where no pointer is implicated, it has no effect whatsoever.

    However, when you assign a derived object to the base pointer, whenever you call a virtual function of the base object, if that function was redefined (what in fact in this case is an overwrite) inside the derived class, the derived class function will be called. While we go through this article, you will learn about abstract classes, pure virtual functions, a method for implementing polymorphic behavior, and ultimately why it is so important for destructors to be virtual.

    We have much to observe and learn, so here we go. Expanding on the knowledge you amassed last week, you will find that, when the function that you call from a base pointer is always going to be decided at run time, the programmers call that dynamic (late) binding. When you call the function from a reference or you call a non-virtual function, that is static binding, and you will not have any polymorphic behavior.

    More C++ Articles
    More By Gabor Bernat


     

    C++ ARTICLES

    - More Tricks to Gain Speed in Programming Con...
    - Easy and Efficient Programming for Contests
    - Preparing For Programming Contests
    - Programming Contests: Why Bother?
    - Polymorphism in C++
    - Overview of Virtual Functions
    - Inheritance in C++
    - Extending the Basic Streams in C++
    - Using Stringstreams in C++
    - Custom Stream Manipulation in C++
    - General Stream Manipulation in C++
    - Serialize Your Class into Streams in C++
    - Advanced File Handling with Streams in C++
    - File Handling and Streams in C++
    - The STL String Class







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek