• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

copy constructor & overload= on template class

stevf

Senior member
Anyone know a couple good online tutorials or resources for figuring out copy constructor and overloading = in a template class?

Last assignment of class is a simple array template class and I have enough of it done to meet the requirements to turn it in but would like to make the copy constructor and = work right. the copy constructor crashes the program the assignment operator i wrote only seems to copy the last element in the array so I currently dont have them in the template and I think that is ok for this assignment but I know it is bad form to not include copy constructor and overload = in a class with pointer variables

Thanks
 
What parts are you trying to figure out? The only thing that makes copy ctors and assignment operators more complex for template classes is that you have to deal with the template type rather than a concrete type. So obviously you can only perform memberwise assignment and/or invoke other semantics that are supported by the generic type T or whatever you're calling it.
 
Those two items werent working correctly - I will read again about those in general again and try it again. I could get the copy constructor to compile if i didn call it but when i tried to instantiate another array using a good array it wouldnt compile and gave indications of a segmentation fault - cant remember exact message VS gave since I am at work now.
edit - this would compile but when trying to run, VS would complain and ask if I wanted to debut or ignore

The = operator would compile and appear to work but when you looked at the new array all of the elements but the last one had bad(as in uninitialized) data and the last element was copied correctly

This makes me think I am missing something simple or one of those gotchas - overloading the [] operator worked easily for me
 
i was mostly looking for sites that people liked that had information of that level as I seem to find sites that are too simple
 
Back
Top