BillLeeLee
[H]F Junkie
- Joined
- Jul 2, 2003
- Messages
- 13,486
Hey all,
I'm a little rusty on my C++ classes, and I have what I think is a pretty basic question.
In my computer graphics textbook, there is sample code given to draw a Sierpinski Gasket.
My question concerns the line:
I know it makes an array of 3 GLintPoint objects, but how does the class know to put a value for x, and a value for y? The class definition doesn't have constructors or anything (and the default constructor is just something like GLintPoint::GLintPoint()). The class is everything that's declared - that is, just with two variables: x and y of type GLint.
And yes, the code works. I had to implement other parts of it, but the code compiles and works correctly.
If anyone could explain what happens with this, I'd be very grateful.
I'm a little rusty on my C++ classes, and I have what I think is a pretty basic question.
In my computer graphics textbook, there is sample code given to draw a Sierpinski Gasket.
Code:
class GLintPoint {
public:
GLint x,y;
}
........
void Sierpinski( void ) {
GLintPoint T[3] = { {10,10}, {300,30}, {200,300} };
int index = random(3);
GLintPoint point = T[index];
drawDot(point.x, point.y);
for(int i = 0; i < 8000; ++i) {
index = random(3);
point.x = (point.x + T[index].x) / 2;
point.y = (point.y + T[index].y) / 2;
drawDot(point.x,point.y);
}
glFlush();
}
My question concerns the line:
Code:
GLintPoint T[3] = { {10,10}, {300,30}, {200,300} };
I know it makes an array of 3 GLintPoint objects, but how does the class know to put a value for x, and a value for y? The class definition doesn't have constructors or anything (and the default constructor is just something like GLintPoint::GLintPoint()). The class is everything that's declared - that is, just with two variables: x and y of type GLint.
And yes, the code works. I had to implement other parts of it, but the code compiles and works correctly.
If anyone could explain what happens with this, I'd be very grateful.