当我想要一个函数返回一个我刚刚定义的struct
类型的向量时,我在设置函数时遇到了麻烦。编译器提供了“使用未声明的标识符”错误。C++类 - 如何从函数返回自定义类型的向量?
在.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
是什么,尽管它在函数之前被声明了吗?
@DeadMG和@mkaes都解决了我的问题。在阅读@mkaes问题的答案后,我也将我的结构声明移到了头文件中,这看起来像是最佳实践。希望这可以帮助别人:) – 2011-05-18 12:03:59