•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 391,572 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,829 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 161 | Replies: 5
![]() |
•
•
Join Date: Jul 2008
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
Last edited by simeon.andreev : 34 Days Ago at 9:49 am.
•
•
Join Date: Dec 2006
Location: india
Posts: 1,045
Reputation:
Rep Power: 9
Solved Threads: 157
http://www.cppreference.com/cppstack/index.html
c++ Syntax (Toggle Plain Text)
#include <stack> struct mystruct { /* whatever */ } ; int main() { std::stack<int> int_stack ; std::stack<mystruct> stack_of_mystruct ; int_stack.push(100) ; // etc. }
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Other Threads in the C++ Forum
- Previous Thread: Decimal Places
- Next Thread: FTP Detailed logs



Linear Mode