gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 20:30:45 26 4
gpt4 key购买 nike

当我想让一个函数返回一个我刚刚定义的 struct 类型的 vector 时,我在类中设置函数时遇到了问题。编译器给出“使用未声明的标识符”错误。

在 .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 是什么,尽管它是在函数之前声明的?

最佳答案

这只是查找的问题。您需要完全限定名称,例如
vector<DeltaKinematics::workingPoint> DeltaKinematics::calculateWorkingPointCloud(){...

关于这个问题我问了一个类似的问题here .也许它对您也很有趣。

关于C++ 类 - 如何从函数返回自定义类型的 vector ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6044151/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com