A ………………….. is used to declare and initialize an object from another object.
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; }
char *get() { return str; }
};
String::String(const char *s)
{
int l = strlen(s);
str = new char[l+1];
strcpy(str, s);
}
int main()
{
String s1("geeksQuiz");
String s2 = s1;
s1.change(0, 'G');
cout << s1.get() << " ";
cout << s2.get();
}
1 Crore+ students have signed up on EduRev. Have you? Download the App |
Destructor is a member function whose name is same as the class name but is preceded by a ………..
We must use initializer list in a constructor when
Whenever const objects try to invoke non-const member functions, the compiler …………………
#include<iostream>
using namespace std;
class Test
{
public:
Test();
};
Test::Test() {
cout << " Constructor Called. ";
}
void fun() {
static Test t1;
}
int main() {
cout << " Before fun() called. ";
fun();
fun();
cout << " After fun() called. ";
return 0;
}
The process of initializing through a copy constructor is known as ……………
#include<iostream>
using namespace std;
class Test
{
public:
Test(Test &t) { }
Test() { }
};
Test fun()
{
cout << "fun() Calledn";
Test t;
return t;
}
int main()
{
Test t1;
Test t2 = fun();
return 0;
}
An ………………….. with a constructor or destructor cannot be used as a member or a union.