template<typename T>
class MyTemplatedClass
{
public:
template<typename P>
MyTemplatedClass(const MyTemplatedClass<P>& rs)
{
__asm { int 3; }
}
};
void main()
{
MyTemplatedClass<int> i;
MyTemplatedClass<int> b = i;//Doesn't call templated CTOR
MyTemplatedClass<double> c = i;//Calls templated CTOR just fine
}
Is this standard template behavior?
I don't have the C++ standard nor the dough to shell out for a copy of it, so I ask those of you who have it:
Is this standard behaviour?
Now this is with MSVC 2005 Express Edition. I expected it to call the templated constructor since P is T. Does the standard say differently?
If you don't define a copy constructor yourself the compiler will define one for you. And it doesn't accept the templated constructor as a copy constructor, you'll have to define one explicitly that does the behaviour you specify.
Quote:Original post by SiCrane
If you don't define a copy constructor yourself the compiler will define one for you. And it doesn't accept the templated constructor as a copy constructor, you'll have to define one explicitly that does the behaviour you specify.
That's what I thought was happening, but I was wondering if that was standard or vender specific as to wether the template could be considered a copy constructor.
This is the normal response:
Template copy constructor is NOT same as normal copy constructor and since u didnt define a normral one (in this case with <typename T>) the compiler make one for you.
See 12.8 in the C++ standard.
Sharon
Template copy constructor is NOT same as normal copy constructor and since u didnt define a normral one (in this case with <typename T>) the compiler make one for you.
See 12.8 in the C++ standard.
Sharon
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement