Jump to content
  • Advertisement
Sign in to follow this  
Raeldor

Smart Pointer Constructor Strangeness

This topic is 4818 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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!