On 2005-03-28, yomgui <no*@valid.com> wrote:
Hi,
The following code compiles on Unix but refuse to do so with devstudio6
can anyone help me to get it right ? (ie for visual studio)
template <class T> class AutoPtr
{
public:
/** Default constructor. */
AutoPtr(T* p = 0);
/** Copy contructing an AutoPtr from another AutoPtr causes the old
one
* to be released from destruction duty. */
AutoPtr(const AutoPtr &a);
/** Copy contructing an AutoPtr from a pointer with a different element
type. */
template<class T1> AutoPtr(const AutoPtr<T1> &a);
}
devstudio says: member function already defined or declared
on the last constructor
Looks like an issue with the compiler -- the parameterized constructor is
*not* a copy constructor.
Here's a question for you -- what is the output of this code on your compiler ?
The template constructor should not be called on copy -- the compiler should
still create one.
/*
template construct ...
conversion construct called!
calling copy construct ...
*/
#include <iostream>
class X {
public:
template <typename T> X(const T& ) {
std::cout << "conversion construct called!" << std::endl;
}
};
int main()
{
std::cout << "template construct ... " << std::endl;
X x(3);
std::cout << "calling copy construct ... " << std::endl;
X y(x);
}
Cheers,
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/