Jumat, 30 September 2016

What is object slicing in c++

Object Slicing   In inheritance we can assign a derived class object to a base class object. But, a base class object cannot be assigned to a derived class object. When a derived class object is assigned to a base class object, extra features provided by the derived class will not be available. Such phenomenon is called object slicing.   Following program demonstrates object slicing: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

The post What is object slicing in c++ appeared first on Coding Security.


What is object slicing in c++
read more

What are virtual constructors and destructors in c++

C++ allows programmers to create virtual destructors. But, it doesn’t allow virtual constructors to be created because of various reasons. To know why a virtual destructor is needed, consider the following program: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 #include <iostream> using namespace std; class A { public: A() { cout<<“A’s constructor”<<endl; } ~A() { cout<<“A’s destructor”<<endl; } }; class B : public A { public: B() { cout<<“B’s

The post What are virtual constructors and destructors in c++ appeared first on Coding Security.


What are virtual constructors and destructors in c++
read more

How to perform object to primitive type conversion in C++

In expressions when there are constants or variables of different types (built-in), one or more types are converted to a destination type. Similarly, user-defined types like classes when used in expressions can also be converted to built-in types or vice versa. Following are the different possibilities of type conversion: Conversion from basic type to class type Conversion from class type to basic type Conversion from one class type to another class type   Conversion from basic type to class type   A value or variable of a basic type or built-in type can be converted to a class member type

The post How to perform object to primitive type conversion in C++ appeared first on Coding Security.


How to perform object to primitive type conversion in C++
read more

Kamis, 29 September 2016

how to perform function overriding in C++

Introduction Polymorphism is one of the key features of object orientation. It means many forms or single interface multiple implementations. Polymorphism is of two types: 1) Compile-time polymorphism and 2) Run-time polymorphism as illustrated in the following figure: Function Overriding When a base class and sub class contains a function with the same signature, and the function is called with base class object, then the function in derived class executes and the function in base class is said to be overridden. This is known as function overriding. Following program demonstrates function overriding: 1 2 3 4 5 6 7 8

The post how to perform function overriding in C++ appeared first on Coding Security.


how to perform function overriding in C++
read more

How to work with constant parameters and members in C++

Constant Parameters and Members Constant Member Functions Member functions in a class can be declared as constant if that member function has no necessity of modifying any data members. A member function can be declared as constant as follows: 1 2 3 4 return–type function–name(params–list) const { //body of function }   Following program demonstrates the use of constant member functions: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 #include<iostream>

The post How to work with constant parameters and members in C++ appeared first on Coding Security.


How to work with constant parameters and members in C++
read more

How to return objects and use of this pointer in c++

Returning Objects   We can not only pass objects as function arguments but can also return objects from functions. We can return an object in the following three ways: Returning by value which makes a duplicate copy of the local object. Returning by using a reference to the object. In this way the address of the object is passed implicitly to the calling function. Returning by using the ‘this pointer’ which explicitly sends the address of the object to the calling function.   Following program demonstrates the three ways of returning objects from a function: 1 2 3 4 5

The post How to return objects and use of this pointer in c++ appeared first on Coding Security.


How to return objects and use of this pointer in c++
read more

Rabu, 28 September 2016

What is array of objects in C++

Array of Objects   As we can create array of basic data types, we can also create an array of user-defined types. An array of objects can be used to maintain details of a group of objects which are stored contiguously in memory. Syntax for creating an array of objects is as follows: ClassName array-name;   For example we can create an array of objects for Student class which can be used to maintain details of a set of students. A single object in an array can be accessed using the subscript or index. Below program demonstrates the use of an array

The post What is array of objects in C++ appeared first on Coding Security.


What is array of objects in C++
read more