write and read from a global vector variable

write and read from a global vector variable

Anonymous
Not applicable
297 Views
4 Replies
Message 1 of 5

write and read from a global vector variable

Anonymous
Not applicable
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
0 Likes
298 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
> acutPrintf("\nNumber of objects so far: %s", MyContainer.size());

acutPrintf() is looking for a string '%s' 🙂
--
|
----+----------------------------------------------
| Byron Blattel
| CADwerx---Applications for AutoCAD
| Autodesk Registered Developer
| email: byron@cadwerx.net
| web site: http://www.cadwerx.net
|
0 Likes
Message 3 of 5

Anonymous
Not applicable
Byron Blattel wrote in news:CFN373165356287963
@discussion.autodesk.com:

>> acutPrintf("\nNumber of objects so far: %s", MyContainer.size());
>
> acutPrintf() is looking for a string '%s' 🙂

(EDITED)... silly me 🙂
but how can I actually solve this??


--
hold your light, Eleven
0 Likes
Message 4 of 5

Anonymous
Not applicable
Byron Blattel wrote in news:CFN373165356287963
@discussion.autodesk.com:

>> acutPrintf("\nNumber of objects so far: %s", MyContainer.size());
>
> acutPrintf() is looking for a string '%s' 🙂

(EDITED)....silly me 🙂

thanx!

--
hold your light, Eleven
0 Likes
Message 5 of 5

Anonymous
Not applicable
Use %d for integers.

"Jeroen Henckaerts" wrote in
message news:A66D0CFC8FD13EDA1BCE9DFA1EAA01C3@in.WebX.maYIadrTaRb...
> Byron Blattel wrote in news:CFN373165356287963
> @discussion.autodesk.com:
>
> >> acutPrintf("\nNumber of objects so far: %s", MyContainer.size());
> >
> > acutPrintf() is looking for a string '%s' 🙂
>
> (EDITED).. silly me 🙂
> but how can I actually solve this??
>
>
> --
> hold your light, Eleven
0 Likes