M
Mona
class myPoly
{
private:
int nv;
double *x, *y;
int *p;
public:
myPoly()
{
x = new double (0);
y = new double (0);
p = new int (0);
nv = 0;
}
myPoly(int n) // number of vertices
{
nv = n;
}
~myPoly()
{
delete x;
delete y;
delete p;
}
void Draw()
{
Read("poly.dat");
for ( int k = 0; k<nv ; k++)
{
int p2 = abs(*p);
if (p2 == nv)
{
for (int l = 0; l<nv;l++)
{
if (*p>0)
{
glBegin(GL_LINES);
glVertex2i(*x,*y);
}
}
glEnd();
}
}
}
void Read(const char s[]) // name of the datafile
{
ifstream infile;
infile.open(s);
int n_count;
double n_x,n_y;
infile>>n_count; //how many vertices
for (int i = 0; i < n_count; i++)
{
myPoly(i);
infile>>n_x>>n_y;
x = &n_x;
y = &n_y;
}
for (int j = 0; j< n_count ; j++)
{
infile >>p[j];
}
infile.close();
}
}
this is my class, and I wonder how come my pointer doesn't point to the
allocated memory?
the nv determines the allocation of memory of each x,y obtained from
the file.
{
private:
int nv;
double *x, *y;
int *p;
public:
myPoly()
{
x = new double (0);
y = new double (0);
p = new int (0);
nv = 0;
}
myPoly(int n) // number of vertices
{
nv = n;
}
~myPoly()
{
delete x;
delete y;
delete p;
}
void Draw()
{
Read("poly.dat");
for ( int k = 0; k<nv ; k++)
{
int p2 = abs(*p);
if (p2 == nv)
{
for (int l = 0; l<nv;l++)
{
if (*p>0)
{
glBegin(GL_LINES);
glVertex2i(*x,*y);
}
}
glEnd();
}
}
}
void Read(const char s[]) // name of the datafile
{
ifstream infile;
infile.open(s);
int n_count;
double n_x,n_y;
infile>>n_count; //how many vertices
for (int i = 0; i < n_count; i++)
{
myPoly(i);
infile>>n_x>>n_y;
x = &n_x;
y = &n_y;
}
for (int j = 0; j< n_count ; j++)
{
infile >>p[j];
}
infile.close();
}
}
this is my class, and I wonder how come my pointer doesn't point to the
allocated memory?
the nv determines the allocation of memory of each x,y obtained from
the file.