Copy Constructors

How would i write the function pro type and definition for a copy constructor?
my attempt is at the bottom of the class. Wasn't really sure about the pointer either...Thanks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class dummyClass
{
public:
void print();
...
private:
int listLength;
int *list;
double salary;
};



dummyClass( const dummyClass& other );


dummyClass( const dummyClass& other )
{
  other.listLength= listLength;
  other.list= list;
  other.salary= salary;
}

}
Last edited on
The declaration and definition looks good, although dont forget to use DumyClass:: if you want to move it to the cpp file.

Also, Im not super familiar with copy constructors but, I believe you want the other.xxxx
on the right side, not left.

1
2
3
listLenght = other.listLenght;
list = other.list;
salary = other.salary;
Aww I think your right that makes sense Thanks
Topic archived. No new replies allowed.