Is this standard template behavior?

Started by
2 comments, last by Sonal 18 years, 5 months ago
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?

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
}

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?
----Erzengel des Lichtes光の大天使Archangel of LightEverything has a use. You must know that use, and when to properly use the effects.♀≈♂?
Advertisement
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.
----Erzengel des Lichtes光の大天使Archangel of LightEverything has a use. You must know that use, and when to properly use the effects.♀≈♂?
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

This topic is closed to new replies.

Advertisement