The problem I need to solve is: create a multitude of Stacks with different types of data.

And what makes it difficult for me is the following: In the multitude there should be all sorts of data stacks. Would it be stacks with integers, chars, objects from user defined classes or whatever. Thus just normal Struct won't help me.

I'm thinking I should use an array of void pointers (void *) but then I get the "is not a pointer-to-object type" message. Until now all I've managed to do is to store the address of the different typed objects. I also thought about pointers to functions in the Stack that would convert the void pointers into pointers I can use ( with dynamic_cast or the (type *) ). However both don't do the trick - still not an object type pointer. Without the <type> for the templated stack I can't think of anything to do.

Putting any code would be useless as all I have a normal templated stack. My question is more kind of: Is there any trick to do it overriding the templates of the different typed stacks? And in general is it even possible to solve this problem?

Sorry if theres another topic with the same question - I do looked hard to find such yet nothing.

Recommended Answers

All 5 Replies

C++ Templates is the key

Using multiple templates would solve my problem if I knew what would go in the multitude. Please give me a better hint if I'm wrong.

having re-read the thread, i realize that my earlier post was asinine.
perhaps you should consider using a programming language that is not statically typed (ideally with some support for reflective programming).

having re-read the thread, i realize that my earlier post was asinine.
perhaps you should consider using a programming language that is not statically typed (ideally with some support for reflective programming).

You have a point. Thank you for the idea.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.