Skip to main content
gamedev.net
🔒 Locked

Vector[0] changing?

Started by Brother Erryn 3 replies 200+ views
Original Post
Brother Erryn
Brother Erryn
My mesh class stores the names of loaded textures, and searches against those before loading one, to avoid loading duplicates. The texture names are stored as: Mesh.at(y).texturename.at(y) After determining if there is a match (or not) and loading the texture (or not), the name of the texture is added using push_back: Meshes[MeshIndex].texturename.push_back(strTexture); strTexture is pulled from the model header with an fread, and put into char strTexture[256] with strcpy. I'm doing the same thing with Meshes[x].name[y], which contains the name of the object (rather than the texture). The problem is that Meshes[x].texturename[y] always returns the current value of strTexture. Meshes[x].name[y] works fine. I know this must be some pointer problem, but I don't know what. Doing this works: char *strTemp=new char[256]; strcpy(strTemp,strTexture); Meshes[MeshIndex].texturename.push_back(strTemp); My impression (being fairly new to C++) is that this isn't a good way to handle memory, but it does in fact work. Question: Can anybody explain to me what's going on here? I want to understand this. [edited by - Brother Erryn on February 19, 2003 10:57:43 PM]
smart_idiot
smart_idiot
Perhaps you would prefer std::string so that you don''t need to worry about pointers?
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other
Brother Erryn
Brother Erryn
Might just do that...but I still want to understand what''s happening.
Brother Erryn
Brother Erryn
Ok, I actually understood that.

But why did .name[y], which was done identically, NOT have this problem?

Nevermind, answered my own question:

tAMFHEADER *Header=(tAMFHEADER*)&buffer[offset];

The Header object contains the object name, and the above line is basically creating a new object each time it''s hit, right?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.