TITLE: template copy constructor?

( Newsgroups: comp.lang.c++.moderated)

KLEIN: "Franz A. Klein"

> I am busy trying to program with template classes. I have declared a copy
> constructor in both the following ways:
>
> Data<T>(const Data &next);
> Data(const Data &next);
>
> Both ways compile without any problems using both Visual C++ 6.0 and
> Borland C++ ver 5.0.  Anybody with a comment or idea as to what is 
> happening or why both versions compile without any errors.

CLAMAGE: Steve Clamage <stephen.clamage@sun.com>

In standard C++, you can have both a template and non-template version
of a function, and they are considered to be different functions:
        template<class T>
                T foo(T t) { ... } // template
        template<>
                int foo<int>(int t) { ... } // explicit specialization
        int foo(int t) { ... }; // ordinary function

The last two lines declare different functions.

Similarly, you can have template and non-template versions of class
member functions. But a template constructor is NOT a copy constructor.
If you declare a template constructor that could be instantiated in
such a way as to resemble a copy constructor, it neverthless is not a
copy constructor. If you do not declare a non-template copy constructor,
the compiler will generate one for you.



_______________________________________________
cpptips mailing list
http://cpptips.hyperformix.com


