Learn about the magic numbers on VS C++: see
Magic Numbers in Visual C++[
^].
You try to be very generic in a language that does not really support this.
You have to employ
void
pointers and book keeping length of elements, cast forth and back a lot. Just not maintainable.
Your code has several other flaws beside the general ones above.
E.g. Disposing does not deal with disposing the stored elements, etc.
If I had to program a stack in C, I'd start with an
int
stack.
If I master this, I would go for a
char[]
(i.e.
char*
) stack where I had to deal with memory ownership (you have to decide who owns the passed element - do you duplicate internally or do you require the client code to duplicate and the stack frees at disposing the stack, or the stack does not own the element, or any other (more obscure) scheme?)).
Only then I would go to do a general-purpose stack class (if really really really needed!). Then you have to make clear how you can bring the
int stack
and the
char* stack
under one hood.
Since you have tagged the question with C++, go and use the
std::stack
class. You re-invent the wheel here. Only justifiable as an exercise to learn that doing so is waste of time ;-).
Cheers
Andi