Science Fair Projects Ideas - Virtual functions

All Science Fair Projects

      

Science Fair Project Encyclopedia for Schools!

  Search    Browse    Forum  Coach    Links    Editor    Help    Tell-a-Friend    Encyclopedia    Dictionary     

Science Fair Project Encyclopedia

For information on any area of science that interests you,
enter a keyword (eg. scientific method, molecule, cloud, carbohydrate etc.).
Or else, you can start by choosing any of the categories below.

Virtual functions


In many object oriented programming languages such as C++, C#, VB.NET, a virtual function is a function that can be overridden with specialized implementations in subclasses.

For example, a base class Animal could have a virtual function eat. Subclass Fly would implement eat differently than subclass Wolf, but you can invoke eat on any base class instance.

This allows you to process a list of objects of class Animal, telling each in turn to eat (by calling eat), with no knowledge of what kind of animal may be in the list. You also do not need to have knowledge of how each Animal eats.

Abstract Class and Pure Virtual Functions

Virtual functions in C++ are functions that will be redefined in derived classes. When defined as null, they are pure virtual functions (example: class B{virtual void apurevirtualfunction() = 0;} ). The presence of pure virtual functions implies that the class containing them is an abstract class, and the function prototype is then used as a stub. The advantage of abstracting a function in this manner is that you do not need to know how the function will be implemented, instead, you only need to know that the module or the abstract class needs a certain functionality. Actual definition can be done later or at the overloaded function of the derived classes. Since they are primarily used as stubs, they are often left empty. For the compiler, they also signal to check the function definition at the derived class first. The compiler creates a list of pointers to all the virtual functions called the vtable or virtual table.


See also superclass, Inheritance_(object-oriented_programming)

10-26-2009 08:16:03
The contents of this article is licensed from www.wikipedia.org under the GNU Free Documentation License. Click here to see the transparent copy and copyright details
Science kits, science lessons, science toys, maths toys, hobby kits, science games and books - these are some of many products that can help give your kid an edge in their science fair projects, and develop a tremendous interest in the study of science. When shopping for a science kit or other supplies, make sure that you carefully review the features and quality of the products. Compare prices by going to several online stores. Read product reviews online or refer to magazines.

Start by looking for your science kit review or science toy review. Compare prices but remember, Price $ is not everything. Quality does matter.
Science Fair Coach
What do science fair judges look out for?
ScienceHound
Science Fair Projects for students of all ages
All Science Fair Projects.com Site
All Science Fair Projects Homepage
Search | Browse | Links | From-our-Editor | Books | Help | Contact | Privacy | Disclaimer | Copyright Notice