C++类 - 如何从函数返回自定义类型的向量?
当我想让一个函数返回我刚刚定义的 struct
类型的向量时,我在类中设置函数时遇到了麻烦。编译器给出“使用未声明的标识符”错误。
在 .h 文件中:(没有给出错误)
struct workingPoint;
public:
vector<workingPoint>calculateWorkingPointCloud();
在 .cpp 文件中:
struct DeltaKinematics::workingPoint {
int x, y, z;
//more stuff to come
};
vector<workingPoint> DeltaKinematics::calculateWorkingPointCloud(){ //error here is "Use of undeclared identifier 'workingPoint'
}
编译器似乎不知道 workingPoint
是什么,尽管它是在函数之前声明的?
I am having trouble setting up my functions in a class when I want to have a function return a vector of type struct
which I have just defined. Compiler gives a "Use of undeclared identifier" error.
In the .h file: (no errors given)
struct workingPoint;
public:
vector<workingPoint>calculateWorkingPointCloud();
And in the .cpp file:
struct DeltaKinematics::workingPoint {
int x, y, z;
//more stuff to come
};
vector<workingPoint> DeltaKinematics::calculateWorkingPointCloud(){ //error here is "Use of undeclared identifier 'workingPoint'
}
It seems that the compiler doesn't know what a workingPoint
is, despite the fact it is declared before the function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这只是一个查找问题。您需要完全限定该名称,例如
向量DeltaKinematics::calculateWorkingPointCloud(){...
我就这个问题提出了类似的问题 在这里。也许这对你来说也很有趣。
It is simply a problem of the lookup. You need to fully qualify the name, e.g.
vector<DeltaKinematics::workingPoint> DeltaKinematics::calculateWorkingPointCloud(){...
I asked a similar question about this issue here. Maybe it is also interesting for you.
您定义了一个结构体
DeltaKinematics::workingPoint
,然后尝试返回一个结构体workingPoint
。您需要明确的资格。You defined a structure
DeltaKinematics::workingPoint
, and then tried to return a structureworkingPoint
. You need the explicit qualification.