Quote:Original post by GuthurHowever, if you use that derived class as a polymorphic base class itself, you might be better off explicitly defining the virtual destructor. I say this because several gcc/ld combinations seem to mess this case up, particularly across DLL boundaries.
I think its refering to the destructor in the derived class; it doesn't need to be explicitly defined as virtual, its implied from the base class.
C++ empty constructor/destructor questions
Quote:Original post by BregmaOh was my terminology a little off?Quote:Original post by iMalc
... and you delete the default constructor ...
How would one accomplish that neat trick?
I mean the constructor that takes no arguments, the one that gets called when you don't provide any arguments. If you've written one of those you find it and press the delete key.
So what should I have called it?
Quote:Original post by iMalc
Oh was my terminology a little off?
I mean the constructor that takes no arguments, the one that gets called when you don't provide any arguments. If you've written one of those you find it and press the delete key.
So what should I have called it?
You are correct it is default constructor but i think what he means is you can delete it all you want, the compiler will still generate a default constructor so it can't be deleted per se :)
Quote:Original post by GuthurBut that's just it, C++ doesn't generate the default constructor if you have defined other constructors.Quote:Original post by iMalc
Oh was my terminology a little off?
I mean the constructor that takes no arguments, the one that gets called when you don't provide any arguments. If you've written one of those you find it and press the delete key.
So what should I have called it?
You are correct it is default constructor but i think what he means is you can delete it all you want, the compiler will still generate a default constructor so it can't be deleted per se :)
Minimal example:
struct X { X() {} // Try deleting this X(int y) {}};X x;
Do people not know this, or was original post misread, or am I just not explaining it right?
iMalc I stand corrected, it does indeed ask for a default to be defined if you have a non default constructor specified but use default constuction. Heres something else though, if you add the () it will compiler eg. A a();, but it will warn that no function of that prototype was found just a useless tibbit :)
[Edited by - Guthur on December 5, 2008 6:04:38 AM]
[Edited by - Guthur on December 5, 2008 6:04:38 AM]
Quote:Original post by iMalc
Do people not know this, or was original post misread, or am I just not explaining it right?
All three, since evidently some people don't know that provide a contstructor, any constructor, will cause the automatically generated ones to not be automatically generated.
My confusion came because I didn't realize you meant that if you had already written a default constructor as well as other constructors, and you then delete the default constructor you had already written, then you will no longer have a default constructor. I gather this might be an artefact of using Visual Studio, like using a single unnamed void parameter instead of an empty parameter list.
The new C++09 language provides a way to explicitly disable automatically generated constructors (and operators). I thought maybe there was a technique in the existing language that did the same thing that I might be unaware of.
Quote:Original post by Bregma
All three, since evidently some people don't know that provide a contstructor, any constructor, will cause the automatically generated ones to not be automatically generated.
No, it's just the default constructor. The compiler will always generate the copy constructor unless you define it yourself even if you provide other constructors.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement