Skip to main content

Posts

Showing posts with the label features of this pointer

Mention features of this pointer. Write a program to demonstrate use of constructor in derived class.

 The this pointer is a pointer that points to the object itself. It is an implicit pointer available in all member functions of a class. Some of the features of the this pointer are: It can be used to refer to the calling object inside a member function. It can be used to return the calling object from a member function. It can be used to pass the calling object as an argument to another function. Here's an example program that demonstrates the use of constructor in a derived class: #include <iostream> using namespace std; class Base {     int x; public:     Base(int i) {         x = i;         cout << "Base constructor called" << endl;     }     void display() {         cout << "x = " << x << endl;     } }; class Derived : public Base {     int y; public:     Derived(int i, int j) : Base(i) {       ...