i derived a class from a linklist class. the problem is i can't access the next or previous pointers.type mismatch.do anybody have an idea how to solve it? should i overload the base class pointers, and how should i go about it?
the program follows.i tried to make it as small as possible so please bear with me!!
Code:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <stdio.h>
#include <iostream.h>
#include <dos.h>
//class definition of link list
class LLClass
{
protected:
class LLClass *next; //pointer to next position
class LLClass *prev; //pointer to previous position
public:
LLClass();
~LLClass();
void setnext(class LLClass *temp);
void setprev(class LLClass *temp);
virtual class LLClass *getnext();
virtual class LLClass *getprev();
};
LLClass::LLClass()
{};
LLClass::~LLClass()
{}
void LLClass::setnext(class LLClass *temp)
{
next=temp;
}//setnext
void LLClass::setprev(class LLClass *temp)
{
prev=temp;
}//setprev
class LLClass *LLClass::getnext()
{
return next;
}//getnext
class LLClass *LLClass::getprev()
{
return prev;
}//getprev
//class definition for class point
class Point
{
private:
int x,y; //top left corner
int color; //color of the box
int direction; //direction the rectangle is going
public:
Point();
~Point();
int xx,yy; //public coordinates
int chcolor; //change in the color
int dir; //the direction of the box
void setvalues(int xx, int yy); //get values for x,y
void setcolor(int chcolor); //change the color
void setdir(int dir); //change the direction
int getx();
int gety();
int getcolor();
int getdir();
int inccolor();
int deccolor();
int incx();
int decx();
int incy();
int decy();
};
Point::Point()
{
x=y=0; //default box at 0
direction=0; //default direction at 0
color=2; //default color green
}//cnstrctr
Point::~Point()
{}
void Point::setvalues(int xx, int yy)
{
x=xx;
y=yy;
}//setvalues
void Point::setcolor(int chcolor)
{
color=chcolor;
}//setcolor
void Point::setdir(int dir)
{
direction=dir;
}//setdir
int Point::getx()
{
return x;
}//getx
int Point::gety()
{
return y;
}//gety
int Point::getcolor()
{
return color;
}//getcolor
int Point::getdir()
{
return direction;
}//getdir
int Point::inccolor()
{
color++;
return color;
}//inccolor
int Point::deccolor()
{
color--;
return color;
}//deccolor
int Point::incy()
{
y++;
return y;
}//incy
int Point::decy()
{
y--;
return y;
}//decy
int Point::incx()
{
x++;
return x;
}//incx
int Point::decx()
{
x--;
return x;
}//decx
//class definition of rectangle
class Rectangle:public LLClass,public Point
{
private:
int b,t;
public:
Rectangle(); //constructor
~Rectangle(); //destructor
class Rectangle *newptr,*first,*last,*curr;//pointers
//functions in class
void setrnext(class LLClass *temp);
class LLClass *convnext(class LLClass *temp);
class Rectangle *getrnext(); //next pointer
class LLClass *getnext(); //next pointer
class LLClass *getprev(); //prev pointer
};
Rectangle::Rectangle()
{}//cnstrctr
Rectangle::~Rectangle()
{}
class LLClass *Rectangle::getnext()
{
return next;
}//getnext
class LLClass *Rectangle::getprev()
{
return prev;
}//getprev
int main(int argc,char *argv[])
{
class Rectangle *first,*last,*curr, *newptr, *temp;
class LLClass *temp;
int rct,choice;
//auto detection
int gdriver = 0, gmode, errorcode;
//initialize graphics
initgraph(&gdriver, &gmode, "c:\\tc\\bgi\\");
//result of initialization
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
//get the number of objects
rct=atoi(argv[1]);
//create first box
randomize();
first=curr=newptr=new Rectangle;
first->setvalues(20+rand()%600,20+rand()%430);
for(int b=1;b<=rct-1;b++)
{
newptr=new Rectangle;
newptr->setvalues(20+rand()%600,20+rand()%430);
//linking
newptr->setprev(curr);
curr->setnext(newptr);
curr=newptr;
}//end of new box (fr)
newptr->setnext(first);
last=newptr;
first->setprev(newptr);
//draw outerbox
choice=0;
rectangle(1,1,630,470);
//problem starts here
//the linklist was created and data was written to it but i can't access it
//draw the small boxes
curr=first;
setcolor(15);
cout<<endl;
for (int j=1;j<=rct;j++)
{
temp=curr->getnext();
curr=curr->getnext();
cout<<newptr->getprev()<<" ";
cout<<newptr->getnext()<<endl;
}//fr
getch();
closegraph();
argc=argc;
choice=choice;
last=last;
return 0;
}
if some one can help via e-mail or thread please do.thx