tags:

views:

120

answers:

3

I'm getting the following error trying to define a list of "Lines":

line-clip.cpp:44: error: expected initializer before '<' token

#include <list>

using namespace std;


class Line {
public:
    Point p1;
    Point p2;
    Line(Point P1, Point P2)
    {
        p1 = P1;
        p2 = P2;
    }
}



// Line List
list <Line> lineList;

How do you define a generic List of type "Line"?

+7  A: 

You need a semicolon after your class declaration :-).

class Line {
    ...
};    // put a semicolon here.
tgamblin
Wow, I've been staring at that for awhile! Thanks!
Such a classic mistake. I think everyone has done this if they've used C++ long enough. And the error messages are always so helpful!
Mark Ransom
I think everyone has done this if they've used C++ for 30 minutes :-). The error messages never get any better... sigh.
tgamblin
Think of how many developer hours have been wasted by the decision to require a semicolon after a class declaration. If they were to not require it in future specs all old programs would still work because it would be seen as an empty statement after the class declaration.
Brian R. Bondy
@Brian Bondy - what would break are things like `class Foo { public: int x; } myFoo;` where a variable is declared as part of the class/struct definition. This is used more often than you might imagine. However, compilers can certainly come up with a better error message for this common error.
Michael Burr
+1  A: 

Your missing a semicolon at the end of your class.

Lomilar
+1  A: 

You are missing a semicolon after your class definition. E.g.

class Line {
 ...
};
Andrew Grant