Sponsored By:
TORUX Software Pvt. Ltd., Pune
THE Experts in Financial Derivatives Software
Journal for GLOBAL GENERATION
Basic Features in C++:
-
Strict type checking:
C++ uses very strict type checking. Therefore a
pointer of any type can hold the object of that type only. The Only
exception to this is a pointer of a base class can hold an object of
the derived class.
- 'this'
Pointer:
This (this)
pointer holds the address of the object of the class. This (this)
pointer is passed as implicit parameter to all member functions
for a class except for static and friend function. This pointer
is not modifiable. The (this)
pointer is also used to guard against self-reference.
-
Name Mangling:
This technique is used by compilers to
generate unique name for identifiers in C++. There are lots of C++
compilers in the market and each compiler follows its own technique
for name mangling. Name mangling ensures that entities with
seemingly identical names still get unique identifications. The
resultant mangled name contains all the necessary information that
may be needed by the linker, such as linkage type, scope, calling
convention, and so on. This technique makes it possible to have
function overloading in C++.
- RTTI (Run Time
Type Information or Run Time Type Identification):
Referring to a C++ system that
keeps information about an object's data type in memory at runtime.
Run-time type information can apply to simple data types, such as
integers and characters, or to generic objects. RTTI information can
be applied to only those classes which are polymorphic which means
that at least one virtual function must be present in the class.
(back to top)
Polymorphism:
Polymorphism is defined as
one interface to control access to a general class of actions. There
are two types of polymorphism,
1. Compile Time Polymorphism
2. Run Time Polymorphism.
-
Run Time Polymorphism
(Function Overriding):
Function Overriding is a
technique that allows a subclass to provide a specific
implementation of a function that is already provided by one of
its super class. For a function to be overridable in derived
class, it must be defined as virtual function in base class.
To define any function as a virtual function we need to use a
virtual keyword before function declaration
virtual void Employee (char* name)
Function overriding is possible due to the introduction of
vtable, which is
class specific. Every object created of that class contains a
pointer to
vtable
called
vptr. The
vtable
contains the
address of virtual function of there corresponding class. If any
derived class does not override any virtual function then
vtable
of derived class
will contain address of virtual function in base classes.
(back to top)
Casting:
-
static_cast:
The static_cast
keyword can be used for any normal conversion between types. This
includes any casts between numeric types, casts of pointers and
references up the hierarchy, conversions with unary constructor.
TYPE
static_cast<TYPE>(object);
-
const_cast:
The const_cast keyword can be used to
remove the const or volatile property from an object. The target
data type must be of the same type as that of the source data types.
TYPE const_cast<TYPE> (object);
-
dynamic_cast:
In C++
dynamic_cast
operator is part of RTTI system that performs a type cast. A wrong
casting may lead to throwing of an exception (dealing with
Reference)
TYPE& dynamic_cast<TYPE&> (object);
TYPE* dynamic_cast<TYPE*> (object);
-
reinterpret_cast:
The reinterpret_cast operator changes one
data type into another. It should be used to cast between
incompatible pointer types.
TYPE
reinterpret_cast<TYPE> (object);
(back to top)
Templates:
It is a feature in C++ which allows a
developer to write a class and function of generic type. The
relation between template class and individual class is same as of a
class and its object. An individual class defines how an object
should be constructed similarly a template class defines how an
individual class should be constructed.
- Function
Templates:
A function template represents a family of functions. It provides a
specification for generating template functions based on some
parameters, which all share the same name and are treated as a unit.
A function template behaves like a function which can accept any
type of argument. They are implemented like regular functions,
except they are prefixed with the keyword ‘template’.
- Class
Templates:
A class template provides a specification for generating classes
based on parameters. A more common use for class templates is the
definition of polymorphic classes, such as containers. Class
function templates are implemented like regular functions, except
they are prefixed with the keyword 'template'.
(back to top)
