Jump to content

  • Log In with Google      Sign In   
  • Create Account


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 mickey   Members   -  Reputation: 100

Like
Likes
Like

Posted 10 January 2002 - 03:26 AM

a. cannot be used as a base class b. results in read-only objects c. must have a virtual destructor d. none of the above which letter is correct? thanks!

Sponsor:

#2 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 10 January 2002 - 04:04 AM



the chicken crosses at midnight..

#3 Sandman   Moderators   -  Reputation: 2079

Like
Likes
Like

Posted 10 January 2002 - 05:25 AM

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.

#4 Digitalfiend   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 January 2002 - 05:31 AM

Let us know how you did on your test/homework...



Dire Wolf
www.digitalfiends.com

#5 mickey   Members   -  Reputation: 100

Like
Likes
Like

Posted 10 January 2002 - 07:19 PM

hehe, sure, it''s a 60 item test, anyway pls, i want a sure answer, anyone?

#6 rapso   Members   -  Reputation: 136

Like
Likes
Like

Posted 10 January 2002 - 07:30 PM

d would be my answer....

#7 Sandman   Moderators   -  Reputation: 2079

Like
Likes
Like

Posted 10 January 2002 - 10:59 PM

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.

#8 Arild Fines   Members   -  Reputation: 968

Like
Likes
Like

Posted 11 January 2002 - 01:54 AM

There''s nothing wrong with TYSC++I21D - it just has a bad title.

Once there was a time when all people believed in God and the church ruled. This time is called the Dark Ages.

#9 MadKeithV   Moderators   -  Reputation: 971

Like
Likes
Like

Posted 11 January 2002 - 02:02 AM

How about

e) Is used to create Singleton classes.




#10 mickey   Members   -  Reputation: 100

Like
Likes
Like

Posted 11 January 2002 - 03:25 AM

okey am just gonna answer....awwwwuuhhh shoot! D!

#11 Sandman   Moderators   -  Reputation: 2079

Like
Likes
Like

Posted 11 January 2002 - 03:47 AM

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.



#12 MadKeithV   Moderators   -  Reputation: 971

Like
Likes
Like

Posted 11 January 2002 - 03:57 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS