If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

structure with a vector as a member

Hello:
I have this interesting problem...
I have to use a c-library that contains a function that is defined as follow:

int func(char * cpData);

I have been using a structure accually a nested structure as follows

struct A
{
char cString;
char cAnotherstring;
}sA;

struct B
{
int iIndex;
float fData[MAXDATA];

}sB;

struct C
{
struct A nA;
struct B nB[8];

}sStream;

I can call this structure with now problems
using
func((char *) &sStream);

The problem happenes when

I wanted to use a vector for the float fData

such as the struct B is as follows:

struct B
{
int iIndex;
vector< float> fData;
} sB;

when I call the function I getting garbaged data.
I do take care of the reserving the appropriate data size for the vector
In fact I can see the data correctly at a point before I used this legecy
function.

Is there a way I can convert somehow to c-array which the function understand
but be able to use the advantage of the vector.

Re: Multi-dimension STL vector

So basically you need to serialize the data stored in the vector? That won't happen though a cast to char*. All that gives you is the memory-layout of the vector class itself, not the data it is storing. The same thing would happen if you had c-style strings (char*) in your structs. You would see the pointer, but not the string it is pointing to.

One solution to this is to implement operator >> and << for your structs to enable serialization to a std::ostream. (Or maybe your own serializer class.) Casting pointers like you do now, is something you really, really should not do if you aren't fully aware of the consequences.

Re: Multi-dimension STL vector

Displaying a 3-dimensional vector on a 2-dimensional monitor is intrinsically difficult, so I would suggest using a 3D graphic library like OpenGL to display it.

But that's just me...

Yeah, thats what we are trying to do actually, were using glut and C++
i think how were gonna manage xyz is a single vector for x, single for y and single for z, just to keep it uncomplicated, then the vertex number would just be associated with the position [i] for any info.