AggrorJorn Posted March 8, 2013 Share Posted March 8, 2013 After some googling I haven't been able to find what I was looking for. What I basicly want to achieve is enter a string and that string is literally the function that I want to run. The thing is I don't want to use a swich that compares if the string is equal to a certain value, and then execute a function. I know this is possible but I haven't found a way of doing this. Can someone please send in the right direction? Thanks Quote Link to comment Share on other sites More sharing options...
paramecij Posted March 8, 2013 Share Posted March 8, 2013 You can't, at least not directly... but there are options, from the top of my head: - use std::map - make your own look-up table and hashing function for strings - use managed c++, it should be similar to how it's done in c# - add reflection to c++ ala www.extreme.indiana.edu/reflcpp/ - use LUA to call your c++ functions - put your functions inside a .dll, then use GetProcAddress() to get a function pointer by string name - i bet the boost lib has something to this effect - probably other ways ... I recommend to just use the STL map container for this. Quote Link to comment Share on other sites More sharing options...
Rick Posted March 8, 2013 Share Posted March 8, 2013 Yeah, in C++ you can't do this directly. I second paramecij to store what you want in a stl map and do it that way. If you want access to C++ members use the Event code I posted in the assets and then you'll be calling events, which you've tied to member functions for created objects, but yeah either way you have to do plumping work like setting up the stl map. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 8, 2013 Author Share Posted March 8, 2013 thanks guys. I will try this tomorrow. Events, delegates and C++ function pointers are new for me, but they are the things that I am looking for. Thanks for the suggestion. Quote Link to comment Share on other sites More sharing options...
Rick Posted March 8, 2013 Share Posted March 8, 2013 I'm telling you, I'm just telling you , use the event file I put up. You don't even fully have to understand the details, just use it in a couple tests and I just think you'll love it. I use it all over the place for soooo many things. It's so handy when programming in C++. It opens up an entire layer of communication between objects. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted March 9, 2013 Author Share Posted March 9, 2013 I will Rick. Ok have downloaded it before but I wasn't using cpp at the time. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.