Buster said:
You have defined a class called "linklist". OK.
You want to define another class, derived from "linklist". OK.
Now you've lost me. Why not? What pointers? How do you "use"
the derived class?
What does it mean to "link" a class?
You _can_ compare a base class pointer and a derived class pointer
for equality. Did you use two equals signs, like `=='?
I shouldn't think so. Without knowing more about the
problem it's impossible to say for sure.
Borrow or buy a better book. There are reviews on the ACCU site.
More recent reviews are more useful because the way people use C++
has evolved. "The C++ Programming Language", 3rd/Special edition,
by Bjarne Stroustrup, covers the whole language nicely. I don't know
that it's very suitable for a beginner.
I tried, really. I don't understand what you are trying to do.
Can you show us the program you are trying to compile?
Post here, read here.
Good luck with that.
here follows the whole program
any help would be appreciated
#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:
oint()
{
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
ublic 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;
}
thx a lot