Skip to content

Tag Archives: C++-Constructors

In C++, if a class has a constructor which can be called with a single argument, then this constructor becomes a conversion constructor because such… Read More
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
<br> #include < iostream ><br> using namespace std;<br><br>    class Test<br> {<br> public:<br> Test() { cout << "Hello from Test() "; }<br> } a;<br><br>   … 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