Different variables for same class

May 16, 2011 at 7:00pm
Hi,

I want to create 7 objects of the same class but in each class, I need to have an array with a unique name for each object.

Is there a way to make this array?
May 16, 2011 at 7:09pm
Why do you want to do this? Isn't an integer with a unique value for each object sufficient as an ID?
May 16, 2011 at 7:24pm
Each object need to have an array with specific vertices.
May 16, 2011 at 7:34pm
Ok, I still don't see why the name of the array should vary among objects.
Isn't something like this good enough?

1
2
3
4
5
6
7
8
9
10
11
12
13
//#include <vector>

struct Vertex
{
    int x;
    int y;
};

struct MyClass
{
    Vertex vertices[10];
    //or std::vector<Vertex> vertices;
};
May 16, 2011 at 7:41pm
Ok..nvm I just was thinking that same name in diferent classes can interfere in calls in some libraries.

For example, a call to this function: http://www.opengl.org/sdk/docs/man/xhtml/glGenBuffers.xml
May 16, 2011 at 7:44pm
That's why we have class objects. So you can have lots and lots of them with the same names for all their internals and there can't be any confusion about which one you mean.
May 16, 2011 at 9:56pm
I'm not sure if I'm understanding you correctly but if I am I have this idea: It doesn't help you functionally at all, and is in fact counter to the main idea behind C++, but you could use typedef to rename the class objects.
Topic archived. No new replies allowed.