Meindert
Computer
- Nov 1, 2003
- 2
I got the run-time error but i dont know how to solve it...please help me, Thanks!
//This is my driver class which used to run my program
//Header File - Draw.h
//Draw.cpp which will add and draw the Triangle
//Header File - Triangle.h
//This is Triangle.cpp file
//Header File - Position.h
//This is Position.cpp file
Thanks for viewing...

//This is my driver class which used to run my program
Code:
#include <iostream.h>
#include "Draw.h"
void main() {
Position p[3];
p[0] = Position (0.0f, 1.0f, -6.0f);
p[1] = Position (-1.0f, -1.0f, -6.0f);
p[2] = Position (1.0f, -1.0f, -6.0f);
Triangle* myTriangle = new Triangle(p);
Draw *draw = NULL;
draw->addTriangle(myTriangle); // call addTriangle function to add a triangle
draw->DrawTriangle(myTriangle);
}
//Header File - Draw.h
Code:
#include "Triangle.h"
class Draw
{
Triangle *T;
Triangle *triangle[50]; // array contains pointers to Triangles
Position *pos;
public:
void addTriangle(Triangle *T);
void DrawTriangle(Triangle *T);
};
//Draw.cpp which will add and draw the Triangle
Code:
#include "Draw.h"
int i=0;
//This function will accept a parameter, pointer to Triangle and places it inside the
//array defined above. (Do i need to enlarge the array if i need to add more?)
void Draw::addTriangle(Triangle *T) {
triangle[i] = T; // run-time error here
i++;
}
void Draw::DrawTriangle(Triangle *T) {
for(int j=0; j<i; j++) {
pos = triangle[j]->getVertices();
}
}
//Header File - Triangle.h
Code:
#include "Position.h"
class Triangle
{
Position position[3];
float red;
float green;
float blue;
public:
Triangle(Position position[]);
void setColor(float red, float green, float blue);
float getRed();
float getGreen();
float getBlue();
Position* getVertices();
};
//This is Triangle.cpp file
Code:
#include "Triangle.h"
Triangle::Triangle(Position position[]):red(1.0), green(1.0), blue(1.0) {
this->position[0] = position[0];
this->position[1] = position[1];
this->position[2] = position[2];
}
void Triangle::setColor(float red, float green, float blue) {
this->red = red;
this->green = green;
this->blue = blue;
}
float Triangle::getRed() {
return red;
}
float Triangle::getGreen() {
return green;
}
float Triangle::getBlue() {
return blue;
}
Position* Triangle::getVertices() {
return position;
}
//Header File - Position.h
Code:
class Position
{
float x;
float y;
float z;
public:
Position();
Position(float x, float y, float z);
float getX();
float getY();
float getZ();
};
//This is Position.cpp file
Code:
#include "Position.h"
Position::Position() { }
Position::Position(float x, float y, float z) {
this->x = x;
this->y = y;
this->z = z;
}
float Position::getX() {
return x;
}
float Position::getY() {
return y;
}
float Position::getZ() {
return z;
}
Thanks for viewing...