【发布时间】:2010-01-30 00:50:14
【问题描述】:
我在编译这段代码时遇到问题。我在 OS X 10.6 上使用 Eclipse 进行编译。该问题似乎仅在使用向量时出现。我似乎根本无法使用 push_back 功能。每次尝试时,我都会收到错误“预期的构造函数、析构函数或类型转换之前。”令牌”。以下是我的代码的一些 sn-ps:
#include <GLUT/glut.h>
#include <vector>
#include <stdlib.h>
#include <iostream>
#include <math.h>
using namespace std;
enum Colour {BLACK =0, RED=1, BLUE=2, GREEN=3, PURPLE=4, ORANGE=5, CYAN=6, BLANK=7};
class Point {
private:
GLfloat xval, yval;
public:
Point(float x =0.0, float y = 0.0){
xval=x;
yval=y;
}
GLfloat x() {return xval;}
GLfloat y() {return yval;}
};
class LinePoint {
private:
Point p;
Colour cNum;
public:
LinePoint(Point pnt = Point(0,0), Colour c = BLACK){
cNum = c;
p = pnt;
}
Point getPoint(){return p;}
Colour getColour(){return cNum;}
};
float turtleScale = 20;
Point turtlePos = Point(300./turtleScale,200./turtleScale);
LinePoint* lp = new LinePoint(turtlePos,BLACK);
vector<LinePoint*> lines;
lines.push_back(lp);
我不确定这是否与 Eclipse 的设置方式有关,但似乎如果我使用位于 here 的代码代替我的向量调用,它仍然会以相同的错误进行编译。
【问题讨论】: