| matheuskiser (5) | |||||||||||||||
|
Hey guys, This is a school project that I am starting to work at. I cannot change the main.cpp and the main.h files. The program is supposed to generally add a Potion Type to a Queue. The potion types are listed in the main.h file as an enum type. The Apothecary class is setting Potion information and queue declarations. My program runs just fine, but it won't add anything to the queue. I have checked my enqueue funtion a million times and I believe I am spot on. (Maybe it's the need for sleep, hehe). Below is my entire code so far. Thank you in advance. Main.cpp
Main.h
Potion.h
Potion.cpp
Apothecary.h
Apothecary.cpp
Queue.h
Thank you so much in advance for reading this ton of code. | |||||||||||||||
|
|
|||||||||||||||
| theranga (100) | |
|
The problem is in the MakePotions and OrderPotion functions. Just to start you thinking, what will Q (OrderPotion, line 158) hold when you call OrderPotion the first time? What will it hold when you call the function a second time? Remember that this is a completely new instance of the function. | |
|
|
|
| matheuskiser (5) | |
|
uhmm ok. So would I have to dynamically allocate Q? So, something like this? queue * Q = new queue; and then go ahead and use Q. Thanks. | |
|
|
|
| cire (2347) | |||
Something like:
| |||
|
|
|||
| matheuskiser (5) | |
|
So I have tried the dynamically allocation of Q so, queue * Q = new queue at line 158. And I have tried the Queue queue instance in Apothecary.h, but both with no successful results.(With this, I'm just adding the Queue queue instance in the .h file and then going to my OrderPotion function and using it like: queue.enqueue(Potion(potion))Am I doing this right? Anything else I can try? Thank you! | |
|
|
|
| cire (2347) | |||
|
It's hard for anyone to tell what you actually did if you don't post the changes you made to your code. You don't say why your results aren't successful. Do you receive an error message from the compiler? Does the program just not behave as you expect it to? Supply enough information for people to help you. If you make the change I suggested above you need to modify Apothecary::OrderPotion and Apothecary::MakePotions:
It's entirely possible that this will result in further bugs in your code being exposed as you've never had more than one item in a queue before. | |||
|
Last edited on
|
|||
| psyclone (1) | |
| Don't you need a queue.cpp? And I don't see a corresponding BuyPotion function. | |
|
|
|
| theranga (100) | |
| @psyclone: the queue member functions are implemented in Apothecary.cpp and for this problem BuyPotion isn't relevant | |
|
|
|