error: expression list treated as compound expression in mem-initializer

Hello again, I'm trying to make a linked list that stores a bunch of shape objects that I created. The shape class is an abstract base class since it's being used as a parent class to a variety of other shape objects - but I've omitted them since they shouldn't pertain to this question.

My main question was in Picture's constructor, the compiler is giving me the error: error: expression list treated as compound expression in mem-initializer [-fpermissive].

It appears I'm getting tons of errors just coming from this one class and struct so I pasted my whole class just in case someone sees something that I didn't write correctly. I suspect all the errors I'm getting are a result of sloppy implementation in all areas on my part.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "Shape.cpp"

class Picture{
    
    public:
        Picture():head(0,0){} // remember to look at your node class and see how many parameters need to be passed to intialize a node
        //you can ONLY have pointers and references to an abstract base class
        
        void insert(Shape *s){head = new ShapeNode(s,head);}
        
        double totalArea()
        {
            double total = 0.0;
            for(ShapeNode p = head; p != 0; p = p->next)
            {
                total += p->info->area();
            }
            return total;
        }
    
    private:
    struct ShapeNode
    {
        Shape *info;
        ShapeNode *next;
        ShapeNode(Shape *newInfo, ShapeNode *newNext) : info(newInfo),next(newNext){}
    };
    ShapeNode *head;
};


1
2
3
4
5
6
7
8
9
10
11
12
13
class Shape {
protected:
  double xCoord,yCoord;
  //third member
public:
	Shape(double x = 0, double y = 0) : xCoord(x),yCoord(y){};
	virtual double getX();
	virtual double getY();
  	virtual double area() = 0;
  	virtual void draw() const = 0;
  	
  	virtual ~Shape();
};
head is a pointer, you can't pass two values to a pointer.
weird, I was talking to someone about that earlier since before I had it as
 
Picture():head(0){}


before and it was giving me errors, I don't know why reversing the change doesn't give me back the same error, though I did change a few things
Last edited on
Topic archived. No new replies allowed.