11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 21Examining Virtual MemberFunctions: Are They for Real?In This Chapter Discovering how polymorphism (a.k.a. late binding) works Finding out how safe polymorphic nachos are Overriding member functions in a subclass Checking out special considerations with polymorphismThe number and type of a function’s arguments are included in its full, orextended, name. This enables you to give two functions the same name aslong as the extended name is different:void someFn(int);void someFn(char*);void someFn(char*, double);In all three cases the short name for these functions is someFn() (hey! this issome fun). The extended names for all three differ: someFn(int) versussomeFn(char*), and so on. C++ is left to figure out which function is meantby the arguments during the call.The return type is not part of the extended name, so you can’t have two functionswith the same extended name that differ only in the type of object theyreturn.Member functions can be overloaded. The number of arguments, the type ofarguments and the class name are all part of the extended name.Inheritance introduces a whole new wrinkle, however. What if a function in abase class has the same name as a function in the subclass? Consider, forexample, the following simple code snippet:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!