Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

DannyB

Creating variables in C++

This topic is 5206 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there anyway to create a variable in the code, name and all? To have a user-defined variable that is declared while the program as running and can be called again later? Right now I''m just using ridiculously long arrays and markers, but I don''t think it is the fastest way.

Share this post


Link to post
Share on other sites
Advertisement
You could via some round about methods, but why in the world would you?

Creating your variables before run-time is the best way to go about it. The compiler doesn''t care how long your variable names are it just sees them as memory addresses anyway.

Share this post


Link to post
Share on other sites
you could make a base object class which holds the data you need, and you could put in there a char* Name; variable, so during runtime you could make a new class and assign its Name variable to Customer_Details or something, and then you would have to have a system where you could later on call Customer_Details class by using a node system or something to check which class out of all of them has Name = "Customer_Details"..... hmmm a bit of a long way round... hope it helps...

Share this post


Link to post
Share on other sites

std::map<std::string,int> intvariables;
std::map<std::string,std::string> strvariables;
// Alternately, create a metatype class that stores float, ints, and strings, then jsut have one map


std::map<std::string,yourmetatype> variables;

Share this post


Link to post
Share on other sites
Use dynamic arrays!
Forget declaring variable names, each element in the array has a number, much easier to manage. If its really necessary you could store the varaible name in a string along with its value in a dynamic array, but I wouldn''t really bother if I were you

Share this post


Link to post
Share on other sites
Well, its not necessary that I am able to define the variable name, but it would be nice. I'm tinkering with those Natural Language Processors, so I need to be able to run several variables as instances through other programs, so in theory, I need to be able to have an infinite number of variables of many different types sent out.

[edited by - DannyB on April 16, 2004 9:50:27 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!