CPP

C++ Preprocessor Operators

What are C++ Preprocessor Operators? Following preprocessor operators are available in C++ that could be used with the #define directive. # is stringify operator turns the operand into a string. Can be used only in macro replacement text. Macro parameter name must follow this operator. ## is concatentation operator to cat preprocessor tokens. Can be …

C++ Preprocessor Operators Read More »

C++ Explicit

What is explicit keyword? A constructor that takes a single argument operates as an implicit conversion operator by default. This is also referred as converting constructor. To prevent this implicit conversion keyword explicit has been introduced in C++. This makes the constructor as non-converting. This keyword has effect only when defined on a single argument …

C++ Explicit Read More »

C++ Preprocessor directives

What are preprocessor directives in C++? C++ supports the following preprocessor directives. #define directive The #define directive replaces all instances of the identifier with the defined string. Identifiers used in comments and part of strings are ignored. To write the #define directive in multiple lines backslash() could be used. In C++ it is better to …

C++ Preprocessor directives Read More »

C++ RTTI

What is RTTI? RTTI stands for Run-time Type Identification. RTTI is useful in applications in which the type of objects is known only at run-time. Use of RTTI should be minimized in programs and wherever possible static type system should be used. RTTI allows programs that manipulate objects or references to base classes to retrieve …

C++ RTTI Read More »

C++ Placement New

What is placement new in C++? In some scenarios it becomes necessary to place objects at specified locations in memory. Placement new solves this problem. For example, there could be predefined memory pools in which certain objects need to be placed on creation. Placement new is achieved by overloading the new operator which takes more …

C++ Placement New Read More »

C++ References

What are references in C++? Reference variables are aliases to other variables. Any changes to the original variable or the alias (reference variable) result in change to the same memory location. Reference variables must always be initialized. When pass by reference is done to functions unlike pass by value a new copy of the variable …

C++ References Read More »

C++ new and delete

How is dynamic memory management handled in C++? C++ supports the operators new and delete for dynamic memory management. These operators perform both allocation/ deallocation of memory and initialization/ cleanup of objects. The class constructor is automatically called when the object is created and the destructor is called when the object is destroyed. The new …

C++ new and delete Read More »

C++ Inline Functions

What are inline functions? Inline functions help to avoid the performance overhead associated with function calling when there are too many calls to a really small function. Code of an inline function would be inserted at every point of function call by the compiler. Adding the keyword inline is just an instruction to the compiler …

C++ Inline Functions Read More »

C++ Object Slicing

What is object slicing? Object slicing is a concept where additional attributes of a derived class object is sliced to form a base class object. Object slicing doesn’t occur when pointers or references to objects are passed as function arguments since both the pointers are of the same size. Object slicing will be noticed when …

C++ Object Slicing Read More »

C++ this pointer

What is this pointer? Every object has a special pointer “this” which points to the object itself. This pointer is accessible to all members of the class but not to any static members of the class. Can be used to find the address of the object in which the function is a member. Presence of …

C++ this pointer Read More »