Tag: OOPs

Limitations on Constructors and Destructors in C++

Limitations on Constructors and Destructors in C++ Limitations on Constructors:- The following are the limitations on constructor functions. Constructor functions should be declared in the public section of the class.  Private and Protected constructors are available only to the member functions and friends of that class. A constructor function does not have any return type, […]

Concept of Data hiding in a class in C++

Concept of Data hiding in a class in C++ In C++, the class groups data members and functions under three access specifiers – private, protected and public, where private and protected members remain hidden from outside world and thereby support data hiding, so that only relevant and required information is exposed to the user and […]

Macro vs. Inline function in C++

Macro vs. Inline function in C++ Functions considerably increase the speed of the program, when it is likely to be called many number of times.  But, if the function is small in size, then it may be defined as inline function which greatly reduces the function calling overheads.  Whenever an inline function is called, the […]

Function scope and File scope in C++

Function scope and File scope in C++ The scope for a function or a variable is determined by the place, where it is declared.  If it is defined within the body of a function then the scope is local to the function or function scope.  For example: if a function named sub() is defined inside […]

Constructors and Destructors in C++

Constructors and Destructors in C++ Constructors: To initialize the data members of a class, Constructors are needed.  A Constructor function is a member function that is invoked automatically when an object of the class is created.  The name of a Constructor function is similar to that of the class name.  It is used to construct […]

Advantages of reference variables over pointers in C++

Advantages of reference variables over pointers in C++ A reference variable is an alias to a variable already defined. After a reference variable is created, the value can be referred to by the original variable or the reference variable. Whenever we declare a reference variable, we need to initialize it at that moment. Take for […]

Polymorphism in C++

Polymorphism in C++ Polymorphism refers to “One Object Many Forms”. It is one of the most important features of OOPs. Polymorphism is implemented through Overloaded operators and Overloaded functions. Polymorphism can be compile time polymorphism or runtime polymorphism. In C++, polymorphism is implemented through virtual functions and dynamic binding. Early binding refers that an object […]

Virtual function – Difference between a Virtual function and an Overloaded function

Virtual function Polymorphism is the property that allows objects of different types to behave differently to the same message. In C++, polymorphism is achieved through virtual functions. Whenever we define a function with the same name in the Base class as well as in the Derived class, the base class pointer, irrespective of pointing to […]

Virtual Base class

Virtual Base Class: A virtual base class is one that is specified as virtual when it is inherited.  If the base class definition precedes the keyword virtual, then it is referred to as virtual base class.  If a situation arises, where the data members of a base class are inherited more than once to a […]

'inline' keyword

Advantage of using the keyword ‘inline’ before a function: The member functions of a class may be defined inside the class definition or outside the class using scope resolution operator. The functions defined inside a class are inline by default. Generally, the functions, which are small, are defined inside a class definition. If a function […]