🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

C++ Workshop - Polymorphism (Ch. 14)

Started by
13 comments, last by Dbproguy 16 years, 1 month ago
Good evening rip-off,

Thanks for the help once again [smile] I really was hoping someone would check my answers out since this was the thoughest one I had to do.

Quote: Original post by rip-off
3) ..., but not always possible/appropriate.

I understood most of what you wrote and didn't think of the solution you gave, but, I'm puzzled as to why or how one wouldn't be able to write a default constructor or why or when they would be inappropriate. Could you give an example when that might be?

Quote:
5) By this do you mean inherit virtually?


Yes, that's what I ment.

Thanks for the link.

Quote:
6) You're wording here is ambiguous (which is understandable, its a difficult subject to put into words).


Yep, really had a hard time in finding a way to write down what I thought to be a good explanation.

I think I understand what you're trying to explain to me, have to sleep a night over it and read it a few times more.

Thanks again rip.
Advertisement
Quote: Original post by J0Be
Quote: Original post by rip-off
3) ..., but not always possible/appropriate.

I understood most of what you wrote and didn't think of the solution you gave, but, I'm puzzled as to why or how one wouldn't be able to write a default constructor or why or when they would be inappropriate. Could you give an example when that might be?

If your class represents a weapon in your game. Does it make sense to have an "empty" weapon? One that doesn't have damage stats or a name? Or an icon?
Imagine if it gets into the final game and the player tries to pick it up. What would happen then?

Since it doesn't make sense to let this happen, perhaps it shouldn't have a default constructor at all. (Because a default constructor would allow me to create such a "blank weapon".)
Instead, it might only have a constructor that takes the necessary data (name, stats and so on), so that you can never create a weapon object that isn't valid.

More generally speaking, it's a good idea to make sure that objects are always in a valid state. If "blank" is not a valid state, then it might be a bad idea to allow "blank" objects to be created.
Quote: Original post by J0Be
Thanks for the help once again


Looking over your post history, yes I do see a bit of a trend [grin]

No problem.
Quote: Original post by Spoonbender
If your class represents a weapon in your game. Does it make sense to have an "empty" weapon?


Yep, got it, thanks Spoonbender.

++rates for both of you gentlemen [grin]

I lost my internet for a few days, but I did get through the book okay. Chapter 14 did seem a little confusing but after a second glance it looked great.
--Dbproguy - My Blog - Tips, Opinions and Reviews about C++, Video Games, and Life

This topic is closed to new replies.

Advertisement