Why we are so confused on c++ virtual function, iterator, and a functor

(Last Updated On: June 15, 2010)
Learn the Secret

Get  our 2 Free Books

Get these now which land directly to their inbox.
Invalid email address

The base type pointer, calls the method but the proper virtual function at runtime is called (dynamically).
Declare a function as virtual in base class, then override it in each derived class, just like redefining, new function must have same signature.
Dynamic binding chooses proper function to call of the virtual address table at runtime, but it only occurs off pointer handles.
A virtual-table is created for every class having one or more virtual functions. The
virtual table is usually implemented as an array of function pointers where each function pointer corresponds to the various implementations of the virtual function by the derived classes.

When an object of this class is created, it contains a virtual-pointer (v-pointer) which points to the start of v-table. Whenever a virtual function is invoked on this object, the runtime system resolves it by following the v-pointer to the v-table to invoke the appropriate function.
Virtual functions are used to extend polymorphic behaviour. VPT:- every class has its own virtual function pointer table. It consist of its virtual functions in an organized way which helps compiler to determine which function to call at run time.

What is pure virtual function? or what is abstract class?
When you define only function prototype in a base class without implementation and do the complete implementation in derived class. This base class is called abstract class and client won’t able to instantiate an object using this base class.
You can make a pure virtual function or abstract class this way..
class Boo
void foo() = 0;
Boo MyBoo; // compilation error

How virtual functions are implemented C++?

What is Virtual Destructor?
Using virtual destructors, you can destroy objects without knowing their type – the correct destructor for the object is invoked using the virtual function mechanism. Note that destructors can also be declared as pure virtual functions for abstract classes.
Multiple providers of libraries might use common global identifiers causing a name collision when an application tries to link with two or more such libraries. The namespace feature surrounds a library’s external declarations with a unique namespace that eliminates the potential for those collisions.
A using declaration makes it possible to use a name from a namespace without the scope operator.

Iterator class that is used to traverse through the objects maintained by a container class. There are five categories of iterators: input iterators, output iterators, forward iterators, bidirectional iterators, random access. An iterator is an entity that gives access to the contents of a container object without violating encapsulation constraints. Access to the contents is granted on a one-at-a-time basis in order. The order can be storage order (as in lists and queues) or some arbitrary order (as in array indices) or according to some ordering relation (as in an ordered binary tree). The iterator is a construct, which provides an interface that, when called, yields either the next element in the container, or some value denoting the fact that there are no more elements to examine. Iterators hide the details of access to and update of the elements of a container class. Something like a pointer.
Functor means function pointers. The pointer variable that holds the address of some function.
Syntax for declaring a functor is: return_type (* nameofFunctor)(parameter_type1, 2, 3, ……);
It means nameofFunctor is a functor that can point to functions taking parameter_type1, 2, 3, ….. and returning return_type
Functors are functions with a state. In C++ you can realize them as a class with one or more private members to store the state and with an overloaded operator () to execute the function.

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!
This entry was posted in Quant Development and tagged , , , on by .

About caustic

Hi i there My name is Bryan Downing. I am part of a company called QuantLabs.Net This is specifically a company with a high profile blog about technology, trading, financial, investment, quant, etc. It posts things on how to do job interviews with large companies like Morgan Stanley, Bloomberg, Citibank, and IBM. It also posts different unique tips and tricks on Java, C++, or C programming. It posts about different techniques in learning about Matlab and building models or strategies. There is a lot here if you are into venturing into the financial world like quant or technical analysis. It also discusses the future generation of trading and programming Specialties: C++, Java, C#, Matlab, quant, models, strategies, technical analysis, linux, windows P.S. I have been known to be the worst typist. Do not be offended by it as I like to bang stuff out and put priorty of what I do over typing. Maybe one day I can get a full time copy editor to help out. Do note I prefer videos as they are much easier to produce so check out my many video at youtube.com/quantlabs