copy constructor and the definition of it

I have some exercises to do in my workbook and I'm stuck on one.

it says:

A) Write the function prototype to include the copy constructor for the class dummyClass.

B) Write the definition of the copy constructor for the class dummyClasss


Suppose you have the following definition of a classs
1
2
3
4
5
6
7
8
9
10
11
12
class dummyClass
{
public:
void print();
...
private:
int listLength;
int *list;
double salary;
string name;
}
A) Write the function prototype to include the copy constructor for the class dummyClass.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class dummyClass
{
public:
dummyClass();                                                     //Default Constructor
dummyClass(int listLen,double sal,string name);//Parameterized Constructor
dummyClass(dummyClass &objdummyClass);    //Copy Constructor
~dummyClass();                                                 //Destructor
void print();

private:
int listLength;
int *list;
double salary;
string name;
};



B) Write the definition of the copy constructor for the class dummyClasss
1
2
3
4
5
6
7
8
9
10
11
12
dummyClass::dummyClass(dummyClass &objdummyClass)
{
	this->name = objdummyClass.name;
	this->salary = objdummyClass.salary;
	this->listLength = objdummyClass.listLength;
	this->list = new int[objdummyClass.listLength];

	for(int i=0;i<objdummyClass.listLength;i++)
	{
		this->list[i] = objdummyClass.list[i];
	}
}
Last edited on
Thank you very much
Topic archived. No new replies allowed.