Message 1 of 5
write and read from a global vector variable

Not applicable
03-01-2002
01:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
hello,
I declared a global vector variable, and it looks like writing to the
vector is never a problem, but reading is sometimes...
I got a class MyClass. The objects of that class are put in a vector:
vector MyContainer. (global variable, is cleared at the
beginning of the program by MyContainer.clear())
When I want to put an object in the class, this is no problem, but when I
read back from the container, something goes wrong.
void Import()
{
// ... get the parameters needed for the new object...
MyClass NewObject(/*..parameters..*/);
MyContainer.push_back(NewObject);
int Number = MyContainer.size() - 1;
// the number of the element just added
// ... some other operations on the object in the container
acutPrintf("\nObject Name: %s", MyContainer[Number].GetName());
// prints the name to the Autocad command line
// this line doesn't cause any problem.
// acutPrintf("\nNumber of objects so far: %s", MyContainer.size());
// at this line, the program crashes... 😞
// if I skip this line, the program continues
for (int i=0; i
acutPrintf("\n\t%s", MyContainer.GetName());
// this line doesn't cause any problem either....
return;
}
It's very strange that at first, it works to enter the container, and
suddenly not anymore...
The errormessage that appears when the program crashes is always
something like this: "FATAL ERROR: Unhandled access violation reading
0x4d64696a Exception at 481d55h".
I think it has something to do with the memory use, but I cannot find the
problem... :(:(
Does anyone know what can be wrong?
Thanks a lot!
jeroen
--
hold your light, Eleven
I declared a global vector variable, and it looks like writing to the
vector is never a problem, but reading is sometimes...
I got a class MyClass. The objects of that class are put in a vector:
vector
beginning of the program by MyContainer.clear())
When I want to put an object in the class, this is no problem, but when I
read back from the container, something goes wrong.
void Import()
{
// ... get the parameters needed for the new object...
MyClass NewObject(/*..parameters..*/);
MyContainer.push_back(NewObject);
int Number = MyContainer.size() - 1;
// the number of the element just added
// ... some other operations on the object in the container
acutPrintf("\nObject Name: %s", MyContainer[Number].GetName());
// prints the name to the Autocad command line
// this line doesn't cause any problem.
// acutPrintf("\nNumber of objects so far: %s", MyContainer.size());
// at this line, the program crashes... 😞
// if I skip this line, the program continues
for (int i=0; i
// this line doesn't cause any problem either....
return;
}
It's very strange that at first, it works to enter the container, and
suddenly not anymore...
The errormessage that appears when the program crashes is always
something like this: "FATAL ERROR: Unhandled access violation reading
0x4d64696a Exception at 481d55h".
I think it has something to do with the memory use, but I cannot find the
problem... :(:(
Does anyone know what can be wrong?
Thanks a lot!
jeroen
--
hold your light, Eleven