Timeline for Problem creating levels using inherited classes/polymorphism
Current License: CC BY-SA 3.0
14 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Sep 29, 2012 at 11:15 | answer | added | jcora | timeline score: 3 | |
| Jan 16, 2012 at 1:40 | comment | added | Adam | Well, I figured out why I was getting a segmentation fault...It was actually because I was trying to load the music before calling Mix_OpenAudio and had nothing to do with the inheritance...I had moved Mix_OpenAudio there because I was reorganizing my code and just kind of forgot about it, so it seemed like the segmentation fault was because of the inheritance. But...Waste of time because I'm going to take your advice and just manage the levels in a single class using level states to check what to do. Thanks for the help. | |
| Jan 16, 2012 at 1:32 | comment | added | Gustavo Maciel | @Adam Easier to think, but it will require a lot more work. | |
| Jan 16, 2012 at 0:49 | comment | added | Adam | @thedaian That was going to be my plan B if I couldn't figure this out...I just figured it'd be easier to manage each level if I had them in their own class. | |
| Jan 16, 2012 at 0:48 | comment | added | Adam | The functions are load(), unload(), etc with code for the level written in them. As for the destructor, would I still want to have it virtual if I just use it in the base class? | |
| Jan 16, 2012 at 0:47 | comment | added | thedaian | This seems... really over-designed. Why do you need to have a new class for each level? That will make it really hard and annoying to add more levels in the future. Ideally, you should have a single level class that can handle loading a variety of different levels. | |
| Jan 16, 2012 at 0:45 | comment | added | Gustavo Maciel | Ah on your destructor, it seems that every child of Level will have a exactly equal destructor, so, i think that would be easier to put that code in the base. | |
| Jan 16, 2012 at 0:44 | comment | added | Gustavo Maciel | What are the "functions have level-specific code in them..."? if the code is just as it is in the question, you doesnt really need to use polymorphism. | |
| Jan 16, 2012 at 0:22 | history | edited | Adam | CC BY-SA 3.0 |
code update
|
| Jan 16, 2012 at 0:21 | comment | added | Adam | I didn't mean to...But I already fixed it and I still have the same problem. | |
| Jan 16, 2012 at 0:14 | comment | added | M Jellyfish | Did you mean to NULL out your pointers in Level1::~Level1 before calling their free functions? | |
| Jan 15, 2012 at 23:56 | history | edited | Adam | CC BY-SA 3.0 |
updated code
|
| Jan 15, 2012 at 23:48 | comment | added | David Gouveia |
Here's a tip about a common C++ rookie mistake you're making. Since you intend to use polymorphism, mark ~Level() as virtual too or you will get into problems when trying to call delete on a Level* pointer.
|
|
| Jan 15, 2012 at 23:23 | history | asked | Adam | CC BY-SA 3.0 |