Jump to content
  • Advertisement
Sign in to follow this  
Erzengeldeslichtes

Is this standard template behavior?

This topic is 4627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!