User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Jul 2008
Posts: 3
Reputation: simeon.andreev is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
simeon.andreev simeon.andreev is offline Offline
Newbie Poster

Mixed type multitude without using Struct

  #1  
34 Days Ago
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.
Last edited by simeon.andreev : 34 Days Ago at 9:49 am.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2008
Posts: 110
Reputation: ivailosp is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 21
ivailosp ivailosp is offline Offline
Junior Poster

Re: Mixed type multitude without using Struct

  #2  
34 Days Ago
C++ Templates is the key
Reply With Quote  
Join Date: Jul 2008
Posts: 3
Reputation: simeon.andreev is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
simeon.andreev simeon.andreev is offline Offline
Newbie Poster

Re: Mixed type multitude without using Struct

  #3  
34 Days Ago
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.
Reply With Quote  
Join Date: Dec 2006
Location: india
Posts: 1,045
Reputation: vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light 
Rep Power: 9
Solved Threads: 157
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: Mixed type multitude without using Struct

  #4  
34 Days Ago
http://www.cppreference.com/cppstack/index.html
  1. #include <stack>
  2.  
  3. struct mystruct { /* whatever */ } ;
  4.  
  5. int main()
  6. {
  7. std::stack<int> int_stack ;
  8. std::stack<mystruct> stack_of_mystruct ;
  9. int_stack.push(100) ;
  10. // etc.
  11. }
Reply With Quote  
Join Date: Dec 2006
Location: india
Posts: 1,045
Reputation: vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light 
Rep Power: 9
Solved Threads: 157
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: Mixed type multitude without using Struct

  #5  
34 Days Ago
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).
Reply With Quote  
Join Date: Jul 2008
Posts: 3
Reputation: simeon.andreev is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
simeon.andreev simeon.andreev is offline Offline
Newbie Poster

Re: Mixed type multitude without using Struct

  #6  
33 Days Ago
Originally Posted by vijayan121 View Post
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Other Threads in the C++ Forum

All times are GMT -4. The time now is 10:24 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC