![]() |
stack question
am i creating a dangling pointer by NOT deleting the array associated with the stackClassDriver objects i'm making?
note: MaxStack is a constant int declared globally (for debugging and shit) here is the class declaration: :
template< class stackType, int MaxStack >here is the definition: :
//push an element onto the stackhere is the driver: note that it repeats for whatever class type they want to make :
int main() |
oh, and any help with making the driver shorter would be welcomed. i tried to use a switch to instantiate the objects before running the choices and stuff, but ran into problems. i thought about polymorphism, but how does that work with templates?
|
I'm going to take a guess and say that you won't have any memory leaks. Since MaxStack is constant, it should be akin to just declaring a static array as a member of the Stack class. Have you tried running it through a debugger or something that watches your memory to see if you get any leaks? IIRC, VC++ will give some notice of dumping unfreed memory when the debugger finishes.
|
You can make your driver shorter by doing something like:
:
while (1)//begin main while |
Quote:
To make the code shorter, you could move the repeated stuff into a template function. |
ok, yeah i wasn't getting any problems with the debugger, and yeah THAT'S the problem i was having with the driver. thanks!
any other thoughts? |
My bad, I should think before I post :o
May be something like this should work: :
int StackItem1; |
Quote:
|
My apologies. I should hang myself :o
|
To make it shorter, put the repeated code into a template function:
:
template <class stackType, int MaxStack> void driverLoop():
if (mainMenuChoice == 1)//begin int stack stackClassDriver |
| All times are GMT -5. The time now is 9:44 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC