dynamic object names

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2008
Posts: 158
Reputation: cam875 is an unknown quantity at this point 
Solved Threads: 3
cam875 cam875 is offline Offline
Junior Poster

dynamic object names

 
0
  #1
Jan 2nd, 2009
I am trying to figure out for my physics simulator how to give my object name a variable or something, ill show an example and the compiler flags it an error but all i am trying to do is pass it the value not the variable

long atomID = 0;
atom atomID;

struct atom
{
short radius;
}

im just trying to get the object of atom to be called 0 so that i can reference all of my objects if lets say the simulator has 100 atoms operating in it at once. but doing it like this I want to be able to create all the atoms like this by just incrementing the atomID so i have a new variable name or something. does anyone have ideas for implementing an idea like this.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: dynamic object names

 
0
  #2
Jan 2nd, 2009
erm did i miss something or do you not just want an array?

atom myAtoms[100];

Chris
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: dynamic object names

 
0
  #3
Jan 2nd, 2009
Did you want an array of atoms?
Possible answers:
1. I don't understand you.
2. You don't know any arrays of...
?
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 158
Reputation: cam875 is an unknown quantity at this point 
Solved Threads: 3
cam875 cam875 is offline Offline
Junior Poster

Re: dynamic object names

 
0
  #4
Jan 2nd, 2009
I have it working with a bunch of vectors but I wanted to see if you can do it with objects from structs, im inexperienced with objects so I want to know how can you have the name of the object change everytime you create a new one.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: dynamic object names

 
0
  #5
Jan 2nd, 2009
Have you ever heard about pointers in C and C++?
What's "the name of the object" in your interpretation? There are anonymous objects in C and C++. Can you post pseudocode with desired "changed names"?
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 158
Reputation: cam875 is an unknown quantity at this point 
Solved Threads: 3
cam875 cam875 is offline Offline
Junior Poster

Re: dynamic object names

 
0
  #6
Jan 2nd, 2009
can the name possibly be a number or something, it has to be something that I can increment by 1 or something before I make another atom object, and yes I have used pointers like once or twice but havent found too much use for them yet in my programming, maybe now is the time

so basically everytime I create an atom object its name has to be slightly different to differentiate between all the atoms created in the simulator.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 570
Reputation: Murtan is a jewel in the rough Murtan is a jewel in the rough Murtan is a jewel in the rough Murtan is a jewel in the rough 
Solved Threads: 93
Murtan Murtan is offline Offline
Posting Pro

Re: dynamic object names

 
0
  #7
Jan 2nd, 2009
This sounds a lot like another recent thread where the developer 'needed' to name the variables based on user input.

The name that you use inside the source need not have anything to do with the name the user sees. It would be your responsibility as the developer to map the elements of the array or vector or whatever other data structure you think would best fit your needs to the names the user is using.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: dynamic object names

 
0
  #8
Jan 2nd, 2009
Well, you have used a compiled, not interpretive language, so "basically everytime you create an atom object its name (and therefore all your program source text) has to be slightly different to differentiate between all the atoms created in the simulator". In other words, you must recompile, relink and reload all your program "everytime you create an atom object". It's cool! Do you find it funny? I do

Think: no source program names at run-time! There are a sequence of machine instructions. What unexistence entities are you intending to change "everytime you create an atom"?
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 489
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Solved Threads: 49
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: dynamic object names

 
0
  #9
Jan 3rd, 2009
Originally Posted by cam875 View Post
can the name possibly be a number or something, it has to be something that I can increment by 1 or something before I make another atom object, and yes I have used pointers like once or twice but havent found too much use for them yet in my programming, maybe now is the time

so basically everytime I create an atom object its name has to be slightly different to differentiate between all the atoms created in the simulator.
Why do they need to have names at all? isn't it simply enough to be able to store un-named atoms in a vector and be able to find them using their position/index within the vector?
The "names" which you see when you're writing your code are for your convenience only - when you send your program through the compiler, those names become non-existant, because your computer doesn't need them - it remembers objects by their 'index' (address) in your computer's memory instead.
¿umop apisdn upside down?
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 158
Reputation: cam875 is an unknown quantity at this point 
Solved Threads: 3
cam875 cam875 is offline Offline
Junior Poster

Re: dynamic object names

 
0
  #10
Jan 3rd, 2009
thats what I have been doing, I was just looking to do it with objects from structs but it doesnt matter anymore.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC