×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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

#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

#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

#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

#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

#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

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

#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...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources