Sign in to follow this  
Super Llama

C++ Array Problem

Recommended Posts

I'm trying to declare a reusable class for mesh storage. I have structs for Vertices and Triangles, both used in a variable-length array as follows:
class Mesh
{
public:
    int VertCount; int TriCount;
    Vert Vertices[];
    Tri Triangles[];
    LPSTR texpath;
};


However, whenever I write to one array, it resets the previous array. For example:
Vertices[0] = CreateVertex(100,50,10);
Vertices[1] = CreateVertex(50,100,30);
Vertices[2] = CreateVertex(10,50,30);
//if I draw the vertex array here, it will show up fine, but it won't be able to connect without the triangles.
Triangles[0] = CreateTriangle(0,1,2);
//now if I try to draw it, only Vertices[2] retains its original position, the other two are zeroed out.


Then I tried:
Vertices[0] = CreateVertex(100,50,10);
Vertices[1] = CreateVertex(50,100,30);
Vertices[2] = CreateVertex(10,50,30);
Triangles[3] = CreateTriangle(0,1,2);


and it all dispalyed fine except Vertices[0]. Vertices[0] was empty. This is a very very very wierd problem, I'm not very used to cpp arrays (this same code worked fine when ported to VB) and I really need some help! If there's a better way to have two non-fixed arrays in a class, that would be great, or if there's some obscure C++ eqivilant to ReDim, that would be even better.

Share this post


Link to post
Share on other sites
How do you declare a vector? I'm using unmanaged C++.

EDIT: Nevermind, I googled it the second after I posted :P

so its like:

vector<Vert> Vertices;

how do you access it once its declared? Vertices<3>?

EDIT:

Lol I googled it again, same as arrays

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this