Hey everyone, so this is my first post, kind of made it because I needed
some help with this program, everything is here. The entire shell of the program is pretty much solid, however in my insert function (line228 and 237) there is a problem, i think mixing up pointers or its NULL or something of the sort. And the same with my print function on (line151),(ignore the cout "yeswthman test function right before it). I've been on this for a while and I think a second mind might be a better idea.
do {
printf("Enter your selection.\n");
printf("\tTo insert a new shape, enter i.\n");
printf("\tTo print all shapes, enter p.\n");
printf("\tTo quit, enter q.\n");
flush();
ch = tolower(getchar());
branching(ch);
} while (ch != 113);
return 0;
}
class ShapeNodeList {
public:
friend class Shape;
Shape *shape;
ShapeNodeList *next;
void flush()
{
int c;
do {
c = getchar();
} while (c != '\n' && c != EOF);
}
void insert()
{
Shape *newShape;
int userShape = 0;
int properI = 0;
printf("What shape would you like to insert? (1: rectangle, 2:square, 3: circle\n");
while(properI == 0)
{
cin >> userShape;
ShapeNodeList *temp;
temp = head;
if (head == NULL)
{
temp->setShape(newShape);
head = temp;
}
you assign head to temp, so if head is null, that means temp is also null. Thus it is guaranteed that when you take the if branch above and try to setShape(), you're dereferencing a null...
should I make the " temp = head;" to "temp = temp->setShape(newShape);", I'm not completely sure I should be inserting at that point. A ShapeNodeList wouldn't be considered null at that point?