within my draw method in the planet class I’m using glTranslated to move the object in a circle (calculated in another method within the class) however I am receiving a run time error “Error: experession cannot be evaluated”. I have messed around with this and what seems to allow the program to run is having -
“circle *loop = new circle[600];” within the draw method.
However when it compiles my planets do not appear. Please help!
This is more a c++ thing. There is a very big memory leak going on here. Currently, you are creating a new local loop array variable in the getCalcPlanetCircle function and you never deallocate it. At the same time, you are accessing the uninitialized member loop variable in the draw function. I suggest you move the allocation/deallocation of your loop array that is
circle *loop = new circle[600];
into the Planet class constructor/destructor like this
Thanks for the reply mobeen, I have corrected my mistakes however I still seem to have the runtime error Experession cannot be evaluated. This error points me to the line “loop[i].x = radius * sin(i/100.0);” within my “Planet::getCalcPlanetCircle()” Method. Any ideas? :S
Could u share how the whole class and the other code looks now (I mean the new updated code so far) seems to me that there are still some uninitialized variables used.
I have moved the For loop to my constructor and removed the need to call the “getCalcPlanetCircle()” method from the main class. That resolved the problem however when I now call the Draw method within the Planet.cpp class Im getting a run time error on glTranslated. It complains about the Loop which is the same error as before. I cant do the same as I did to the getCalcPlanetCircle method :S
Main class:
// Draw planets
for (int i = 0; i < planetNum; i++)
{
planet[i]->draw();
}
Planet.h:
#ifndef PLANET_H
#define PLANET_H
#include <iostream>
#include <string>
#include "Structures.h"
using namespace std;
class Planet
{
private:
string name;
position pos;
circle *loop;
int slices;
int stacks;
int r;
int g;
int b;
float rot;
float radius;
float rotIndex;
float speed;
public:
Planet(string Pname, float Pradius, int Pslices, int Pstacks, position Ppos, float ProtIndex, int Pr, int Pg, int Pb)
: name(Pname), radius(Pradius), slices(Pslices), stacks(Pstacks), pos(Ppos), rotIndex(ProtIndex), r(Pr), g(Pg), b(Pb)
{
cout << "Planet " << Pname << " created" << endl;
circle *loop = new circle[600];
int derp = 5;
for (int i = 0; i < 600; i++)
{
loop[i].x = radius * sin(i/100.0);
loop[i].y = 0;
loop[i].z = radius * cos(i/100.0);
}
}
~Planet();
string getname();
position getPosition();
float getRot();
float getradius();
float getslices();
float getstacks();
float getRotIndex();
void getCalcPlanetCircle();
void update();
void draw();
};
#endif