Kat*_*nie 1 c++ templates compiler-errors
我看了一遍,我找不到任何与我的问题有关的事情.我试图为一个多边形类编写一个类定义,该类基本上有一个包含指向点的指针的向量.当我尝试编译时,我会继续解决以下错误...
错误C2143:语法错误:缺少';' 在'<'错误之前C4430:缺少类型说明符 - 假定为int.错误C2238:';'之前的意外标记 错误C2061:语法错误:标识符'向量'错误C2065:'myPolygonPoints':未声明标识符错误C2065:'points':未声明标识符错误C2065:'myHasInstersection':未声明标识符错误C2660:'Polygon :: addSetOfPoints':函数不拿一个参数
这是该类的代码
#include "Point.h"
#include <vector>
class Point;
class Polygon
{
private:
vector<Point*> myPolygonPoints;
bool myHasIntersection;
public:
void addSetOfPoints(vector<Point*> points)
{
myPolygonPoints = points;
}
bool getHasIntersection()
{
return myHasIntersection;
}
void setHasIntersection(bool intersection)
{
myHasInstersection = intersection;
}
};
Run Code Online (Sandbox Code Playgroud)
您正在使用vector
从std
命名空间,而不必限定它.
您要么必须执行using namespace std;
,要么使用命名空间using std::vector
声明所有vector
对象,std
例如std::vector
.
#include "Point.h"
#include <vector>
class Point; // Assuming Point.h has this declared,
// you don't need this forward declaration, but in reality,
// you don't need to include Point.h
// since you're only declaring pointers to Points
class Polygon
{
private:
std::vector<Point*> myPolygonPoints;
bool myHasIntersection;
public:
void addSetOfPoints(std::vector<Point*> points)
{
myPolygonPoints = points;
}
bool getHasIntersection()
{
return myHasIntersection;
}
void setHasIntersection(bool intersection)
{
myHasInstersection = intersection;
}
};
Run Code Online (Sandbox Code Playgroud)