Skip to content

Tag Archives: C++-Constructors

In this article, we will discuss the Dynamic initialization of objects using Dynamic Constructors. Dynamic initialization of object refers to initializing the objects at a… Read More
In Object Oriented Programming, Objects are the instances of a class which has its own state(variables) and behavior(methods).  Every class has two special methods related… Read More
Prerequisites: l-value and r-value references in C++, Copy Constructor in C++. What is a Move Constructor?   The copy constructors in C++ work with the… Read More
Constructor: A constructor is a member function of a class that has the same name as the class name. It helps to initialize the object of… Read More
A recursive and a non-recursive program to delete an entire binary tree has already been discussed in the previous posts. In this post, deleting the… Read More
#include<iostream> using namespace std;    class Test { public:    Test(Test &t) { }    Test()        { } };    Test fun() {     cout << "fun() Called\n";… Read More
Predict the output of following program? #include <iostream> using namespace std; class Test { private:     int x; public:     Test(int i)     {         x = i;         cout… Read More
#include<iostream> using namespace std;     class Test { public:   Test(); };     Test::Test()  {     cout << " Constructor Called. "; }     void fun() {… Read More
Which of the following is true about constructors. 1) They cannot be virtual. 2) They cannot be private. 3) They are automatically called by new… Read More
We must use initializer list in a constructor when (A) There is a reference variable in class (B) There is a constant variable in class… Read More
Predict the output of following program. #include<iostream> using namespace std; class Point {     int x; public:     Point(int x) { this->x = x; }     Point(const Point… Read More
Output? #include<iostream> #include<string.h> using namespace std;    class String {     char *str; public:      String(const char *s);      void change(int index, char c) { str[index] = c;… Read More
#include <iostream> using namespace std;    class Test { public:       Test() { cout << "Hello from Test() "; } } a;    int main() {… Read More
Predict the output of following program. #include<iostream> #include<stdlib.h> using namespace std;    class Test { public:    Test()    { cout << "Constructor called"; } };   … Read More
#include <iostream> using namespace std;    class Point {     int x, y; public:    Point(int i = 0, int j = 0) { x = i;… Read More