Archived

This topic is now archived and is closed to further replies.

mickey

pls answer this... A class that has a protected constructor:

Recommended Posts

c or d.

AFAIK there is no rule in the C++ language that says "If Thou Maketh A Class With A Protected Constructor, Thine Destructor Must Be Virtual", but since a class with a protected constructor is most likely an ADT from which you are deriving other useful classes, it is probably a good idea.

Share this post


Link to post
Share on other sites
Well it''s a crap question. There is no requirement in the C++ language that a class with a protected constructor should have a virtual destructor, but in 99% of cases it is common sense. (off the top of my head, I can''t think of any cases where it isn''t common sense, can anyone else?)

So the correct answer depends on your teacher. If he is

a) a tosser who learnt C++ from ''Teach Yourself C++ in 21 days'' and is giving you questions directly out of the book, then the answer is probably c.

or

b) a tosser who actually knows and understands the syntax, but wants to ask you a trick question. In this case, the answer is d.

I''d put my money on c, even though technically d is the correct answer.

Share this post


Link to post
Share on other sites
quote:
Original post by MadKeithV
How about

e) Is used to create Singleton classes.





Surely you would make the constructor private, unless you were planning to derive classes from it.....

....in which case you would probably want a virtual destructor.

Share this post


Link to post
Share on other sites
Hahah sandman, yes, indeed!

DEFINATELY any class that is not 100% certain to never be derived should have a virtual destructor. I''ve seen some really nasty bugs with that one, from code that was "tried and true" according to other people. Ick!

People might not remember what you said, or what you did, but they will always remember how you made them feel.

Share this post


Link to post
Share on other sites