UML Notations

Realization   Instantiation   Uni-Directional Association   Bi-Directional Association   Composition by Value   Composition by Reference   Generalization

C++ Copy Constructor

What is a copy constructor? The default copy constructor created by the compiler performs a bitcopy. When the class members are dynamically allocated it becomes necessary to write our own implementation of copy constructor. The copy constructor essentially performs a deep copy when a object is created using another object. EXAMPLE: Demostrates the need of …

C++ Copy Constructor Read More »

C++ Friends

What is a firend function/ class? A friend is permitted full access to private and protected members. A friend can be a function. A friend can be an entire class. In this case all member functions of the class are given access. EXAMPLE: Demonstrate the usage of friend function #include <iostream>using namespace std;class Check {int …

C++ Friends Read More »

C++ Abstract Base Class

What is Abstract Base Class? Allows the base class to provide only an interface for its derived classes. Prevents anyone from creating an instance of this class. A class is made abstract if atleast one pure virtual function defined. EXAMPLE: Demonstrate the definition of a abstract base class #include <iostream>using namespace std;class MyInterface {public:virtual void …

C++ Abstract Base Class Read More »

C++ Free Compilers

MINGW Compiler MinGW – Minimalist GNU for Windows . A native Win32 port of the GNU Compiler Collection (GCC), with freely distributable import libraries and header files for building native Windows applications. Free download in the following link. http://www.mingw.org/wiki/Getting_Started Download “Automated MinGW Installer” EXE from this link. This will help in automatic download install of MINGW. …

C++ Free Compilers Read More »

C++ Virtual Destructor

What is a virtual destructor? Virtual destructor ensures that the object destruction happens from the most derived class towards the base class. Significant in scenarios where a derived class object is assigned to a base class pointer. EXAMPLE: Demonstrate the object destruction sequence. #include <iostream>using namespace std;class Base {public:Base() {cout << “Base class constructor …” …

C++ Virtual Destructor Read More »

C++ Operator Overloading

What is Operator Overloading? Mimics conventional usage of operators for user defined types. Operator :: (scope resolution), . (member selection) and .* (member selection thru pointer to function) cannot be overloaded. EXAMPLE: Demonstrate the usage of operator overloading #include <iostream>#include <ostream>using namespace std;class Employee {private:int iEmpId;string iEmpName;public:Employee(int, string);friend ostream& operator<<(ostream&, const Employee&);};// ConstructorEmployee::Employee(int aEmpId, string …

C++ Operator Overloading Read More »

C++ Singleton

Singleton Singleton is a creational design pattern. A design pattern to provide one and only instance of an object. Make the constructors of the class private. Store the object created privately. Provide access to get the instance through a public method. Can be extended to create a pool of objects. Sample Program #include <iostream>using namespace std;// …

C++ Singleton Read More »

C++ Diamond Problem

What is the need for Virtual base classes? Required in scenarios of multiple inheritance where the derivation is like diamond. Compiler reports an error since there is a ambiguity since the derived class (Derived3) sees 2 instance of base class (Base). Using the keyword virtual in the derived classes (Derived1, Derived2) resolves this ambiguity by …

C++ Diamond Problem Read More »

C++ Exception Handling

What is Exception Handling? Exceptions are run-time program anomalies.Exception handling provides a standard mechanism to handle such anomalies. When a exception is raised the normal program execution is suspended until it is handled. Raising of an exception is done by “throw” expression. Handling of an exception is dobe by the “catch” clause. “Try” block groups …

C++ Exception Handling Read More »