C++类 - 如何从函数返回自定义类型的向量?

发布于 2024-11-08 04:44:02 字数 554 浏览 5 评论 0原文

当我想让一个函数返回我刚刚定义的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝戈者 2024-11-15 04:44:02

这只是一个查找问题。您需要完全限定该名称,例如
向量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.

鲸落 2024-11-15 04:44:02

您定义了一个结构体 DeltaKinematics::workingPoint,然后尝试返回一个结构体 workingPoint。您需要明确的资格。

You defined a structure DeltaKinematics::workingPoint, and then tried to return a structure workingPoint. You need the explicit qualification.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文