LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-29-2006, 04:54 PM   #16
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled

not to hijack the thread but that response really made me laugh.
 
Old 12-29-2006, 06:06 PM   #17
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
Quote:
Originally Posted by dmail
Have you overloaded the equal operator? otherwise you are trying to reset a reference which is not allowed. There are many more questions I could ask but I think it maybe better to see your code.
Well this is actually almost the same thing I wanted when I created this thread, just that now I am parsing a file and the first word on a certain line contains a word that will be converted into a number.

So I have a function which converts a list of text strings to a number between 0 and 12. Just like when you #define stuff, just that now I can't use the preprocessor.

Anyway, I realized that if a person starts to modify the file he or she may not write each line in order. Well, I will try to explain a little better:

The file looks like this:
Code:
# comments
[ModelName]
STAND VX_HEAD 0 1 2 3
STAND VX_HEAD 1 2 3 4
STAND VX_HAND 0 1 1 1
STAND VX_LEG 0 3 2 1

WALK VX_HEAD 0 1 1 1
WALK VX_HAND 0 2 1 4
...

[AnotherModelName]
...
I then parse the file, the first word is the state, which translates into a number. I need the index number in the vector to reflect to that number. So if STAND is 3 and WALK is 2, I need the verteces for STAND to be added to the 3rd index in the vector (the vector contains a number of instances of the class ModelAniType, where each instance takes care of a certain state, like walk or stand).

I could have solved this with push_back, but that requires that the state that translates into 0 should be first in the file, next the state that translates into 1, and so on. So that the ModeAniType instances get pushed onto the vector in the correct order.

I need something more dynamic than that. So I want to make the vector grow as it needs and then play with the item at index function_state2int(STATE).

Does anyone understand what I am talking about? :P

Thanks,

Last edited by Ephracis; 12-29-2006 at 06:09 PM.
 
Old 12-30-2006, 01:55 AM   #18
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Have a look at the map data type (I'm sure that's the one) it is what other languages call an associative array and will allow you to specify the index (or key). In your situation the key will be an integer but it can be any data type, possibly an enum?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Memory Allocation jvff Programming 1 09-05-2005 05:01 AM
dynamic memory allocation failure guam Programming 4 04-13-2005 09:16 AM
G++ memory layout of the classes shibdas Programming 4 09-20-2004 07:17 AM
pointers and dynamic memory allocation deveraux83 Programming 2 01-24-2004 10:35 AM
C++ dynamic classes tristan_vdv Programming 1 01-04-2002 04:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration