Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run-time error...pls help me to solve it!

Status
Not open for further replies.

Meindert

Computer
Nov 1, 2003
2
I got the run-time error but i dont know how to solve it...please help me, Thanks!

error.jpg


//This is my driver class which used to run my program
Code:
#include <iostream.h>
#include &quot;Draw.h&quot;

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 &quot;Triangle.h&quot;

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 &quot;Draw.h&quot;

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 &quot;Position.h&quot;

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 &quot;Triangle.h&quot;

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 &quot;Position.h&quot;

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...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor