Advertisement Jump to content
Sign in to follow this  
Raeldor

Smart Pointer Constructor Strangeness

This topic is 4888 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

Hi, I am writing my own smart pointer class, which seems to be working so far, but I was a little confused as there was a point I was expecting the compiler to complain when it didn't. I have the test code...
	MyTest* test2=new MyTest();
	MyTestPtr testp1=test2;
	MyTestPtr testp2=test2;
	MyTestPtr testp3=testp2;

which works fine when I have the constructors...
	SmartPointer(T* in_object);
	SmartPointer(SmartPointer& in_smartPointer);

but when I comment out the second constructor it STILL works. Why wouldn't the last line on the first section of code (MyTestPtr testp3=testp2) fail if there wasn't a constructor for the SmartPointer? BTW, MyTestPtr is just a typedef for a smart pointer to the test class MyTest (ie typedef SmartPointer<MyTest> MyTestPtr). Thanks

Share this post


Link to post
Share on other sites
Advertisement
It's probably writing a default copy constructor for you, which, with smartpointers, or anything that holds a pointer, is bad. Don't comment out that constructor.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!