Cpp Tutorial: Exception Handling in C++
An exception is an error condition that occurs during run time. Generally without exception handling, the program will crash when there is an exception. We place the code where the exception might occur and we handle that exception without crashing the program. C++ provides 3 types of exception handling keywords: try, catch, throw. try: We […]
Cpp Tutorial: Structure Padding and Bitfields in C++
In this chapter we shall look at below topics: What will be the size of structure in below example? Now why we add extra bytes? How to avoid structure padding? Structure Packing: Bitfields in C++ Before we look at Structure Padding and Structure Packing, let’s see an example below: What will be the size of […]
Cpp Tutorial: C++ structure padding and packing
In this tutorial we shall learn about structure padding. We shall learn below topics: What is structure padding? How to avoid structure padding? How to avoid structure padding using a macro? 1. What is structure padding? Padding is a concept to add more bytes to structure or class, so that the accessing will be easier. […]
Cpp Tutorial: C++ Structure
Till now we have seen everything about classes. Now we shall see in-depth on C++ Structures. In this chapter we shall learn about below topics in C++: Structure Introduction: How to define a structure? How to create structure variable? Example for a structure with constructor, member function and data member. Difference between C structures and […]
Cpp Tutorial: Class template with Overloaded Operators and template Inheritance in C++
In this chapter we shall see below topics: 1. Class template with overloaded operators 2. Template Inheritance 1. Class template with overloaded operators It is possible to use operator overloading with class template. Below example will show how to achieve the same. Example: #include <iostream> // for more tutorials visit www.ProDeveloperTutorial.com using namespace std; template […]
C++ Tutorial: Class Template in Cpp
In this tutorial we shall see below topics. 1. Class Template 2. Class Template with more parameters 1. Class Template Syntax for class Template template <class T> class <class_name> { }; In the below example we shall see a program without using class template and with using class template. Example without using class template. #include […]
Cpp Tutorial: Function Template in C++
In this tutorial we shall learn about below topics Introduction to Function template Syntax for function template: Example for simple function template Function Template with more arguments Overloading function template Recursion with function template 1. Introduction to Function template The function defined outside a class is called as normal functions. Generally normal function will work […]
Cpp Tutorial: Introduction to template programming in C++
In this tutorial we shall learn about below points: 1. Introduction to template programming. 1. Templates are very important topic in C++. With the help of templates we can write functions that will work with any type of data types. 2. A function that works with any data type is called as generic function. 3. […]
Cpp Tutorial: Different types of Member Functions in C++
Below are different types of member functions available in C++ 1. Simple member functions 2. Static member functions 3. Const member functions 4. Inline member functions 5. Friend functions 1. Simple member functions: The function defined inside a class without any kind of keyword delared are called as simple member functions. Example: #include <iostream> // […]
Cpp Tutorial: Upcasting and downcasting in C++
Upcasting: It is the process of converting derived-class reference or pointer to the base class. Downcasting: It is the process of converting base-class reference or pointer to the derived class. Upcasting: Here the derived class pointer is converted to base class. This is allowed in inheritance. There is no need of explicit typecasting. There is […]