Skip to main content
gamedev.net
🔒 Locked

Smart Pointer Constructor Strangeness

Started by Raeldor 0 replies 450+ views
Original Post
Raeldor
Raeldor
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
stylin
stylin
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.
:stylin: "Make games, not war." "...if you're doing this to learn then just study a modern C++ compiler's implementation." -snk_kid

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.