| Farrukh12 (25) | |||||||||
.h file
My .cpp file
Whenever I Call the following in main .cpp
it display the following error.
Note: I cannot change the prototype of the function insertAtHead(). | |||||||||
|
|
|||||||||
| coder777 (2550) | |||
in your copy constructor you copy the data to the other list. But you want to copy it from that list. In other words you have to wirte it like so:
| |||
|
|
|||
| Farrukh12 (25) | |
| No, I am trying to copy data to the other list. Not form the other list | |
|
|
|
| guestgulkan (2916) | |||
In which case I think you completely misunderstand what the copy constructor is for and the circumstances in which the compiler will call it. | |||
|
|
|||
| HiteshVaghani1 (207) | |
| First thing if you are using Template for your program than make sure that Declaration and Definition must go in the same file... | |
|
|
|
| Farrukh12 (25) | |||
Not necessarily I can call .h file in the .cpp like
| |||
|
|
|||
| Farrukh12 (25) | |
| @guestgulkan: can you please explain how? | |
|
|
|
| HiteshVaghani1 (207) | |
|
Hey Farrukh i know that... please read Templates and multiple-file projects From http://www.cplusplus.com/doc/tutorial/templates/ | |
|
|
|
| guestgulkan (2916) | |||||||
|
The copy constructor is used to initialise a new object under construction from the values of an exixting object. Example 1;
Example 2;
The copy constructor looks something like this:
So - the this object will be anotherT and const T& other parameter will be the existing object - in this case someT. As the anotherT object is the one being created/initialised it's values are all nonsense - the whole idea is to intitialise it from the values of the existing object passed as the function parameter. So copying values from anotherT (under construction) to someT (existing object) doesn't make sense (and could cause segfaults/memory access violations.) | |||||||
|
|
|||||||
| kaidto (12) | |||
|
Copy constructors are used the entire block of memory of some object. For example! if you have data stored inside an object, but you want it not to be pointed out, but copied instead. you should Copy construct it.
myNewFoo will have a fresh copy of what you passed to CopyFooYou have to delete the newly created object when you finish using it, since it was allocated in the heap trought newRegards! | |||
|
|
|||
| Farrukh12 (25) | |
| Thank You All of You, I found my mistake | |
|
|
|