简单的 C++矢量/指针失态
这绝对是非常简单的。我已经离开 C++ 几年了,所以我需要一些帮助来弄清楚为什么它无法编译。
我有一个名为“PointList”的课程。在头文件中,我有以下内容:
public:
PointList();
private:
std::vector< Point* > *pl;
在 .cpp 文件中,我有以下内容:
PointList::PointList()
{
pl = new vector< Point* >();
}
这不会编译。
“向量”之前的预期类型说明符
无法在赋值中将“int*”转换为“std::vector <*”
预期的 ';'在“矢量”之前
给出了什么?
This is definitely really simple. I have been out of C++ for a few years, so I need some help with figuring out why this won't compile.
I have a class called 'PointList'. In the header file, I have the following:
public:
PointList();
private:
std::vector< Point* > *pl;
In the .cpp file, I have the following:
PointList::PointList()
{
pl = new vector< Point* >();
}
This does not compile.
Expected type-specifier before 'vector'
Cannot convert 'int*' to 'std::vector <*' in assignment
expected ';' before 'vector'
What gives?
您是否使用
using
声明。如果没有,您需要在 cpp 文件中为vector
加上namespace std::
前缀Are you using
using
declarations. If not you need to prefixvector
withnamespace std::
in your cpp file