is not a call to the copy constructor; it is a call to operator() [the function call operator] with a
parameter of v1.
You need to do as R0mai typed.
BTW, as a matter of good practice, it is not a good idea to implement copy construction by
way of assignment; rather, for exception safety reasons, the reverse is usually done.
Coincidentally, I am working with ATL right now. Examining code of CComVariant to make sure I was doing things right, I found out that at least one of the constructors make use of the overloaded operator=():
Therefore, I am now interested as well to hear why the reverse is usually done. A quick search found nothing relevant, but again, I may be looking in the wrong places... er... keywords. :-P
But I do not believe templated copy constructors are allowed, or atleast work for all situations,
I.e. if class "Generic" is an array of pointers, the copy would fail to produce the correct results as it would if "Generic" were an int. So for templated class, it may be best to have explicitly defined copy constructor for odd cases (i.e. non-predefined types).
The thing is, the copy constructor for T1<T2> will only take a T1<T2> as its parameter rather than T1<T3>. If copy constructors for template classes weren't allowed, the entire STL could not exist.
I think iharrold might have been referring to making the copy constructor itself a templated constructor.
Which is of course not allowed, and even nonsensical, since a copy constructor has a very specific
signature.
I will try to write an article about copy constructors and how to build exception safe assignment operators
(via copy-swap).
The implementations are illogical. You've written the assignment operator with the assumption that it is only used for copy construction which is wrong. It doesn't check for self assignment, doesn't clear the LHS container, and so forth. The implementation is conceptually wrong. As far as the copy/swap idiom goes that is another story. You could use that but don't have to. first you have to study the concept of the assignment operator so that you understand every circumstance for which it is needed. What you currently have is totally wrong for a variety of reasons.