CPP

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++ 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++ 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++ 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++ 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 »

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 »