C++类 - 如何从函数返回自定义类型的向量
C++ classes - how return vector of custom type from a function?
当我想让函数返回我刚刚定义的类型 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
是什么,尽管它是在函数之前声明的?
这只是查找的问题。您需要完全限定名称,例如
vector<DeltaKinematics::workingPoint> DeltaKinematics::calculateWorkingPointCloud(){...
我在这里问了一个关于这个问题的类似问题。也许这对你来说也很有趣。
您定义了一个结构DeltaKinematics::workingPoint
,然后尝试返回一个结构workingPoint
。您需要明确的限定条件。
相关文章:
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- flutter:即使shouldRepaint()返回true,自定义画家也不会重新绘制
- 通过 NIF 从C++返回自定义数据结构
- QtQuick - qml:28:错误:未知方法返回类型:自定义类型
- 如何在C++中返回自定义类中的分段错误?
- 如何在C++中允许成员函数的自定义返回类型进行类型擦除?
- 如何从 cpp 中的函数返回自定义类对象?
- 将成员函数的返回类型引用到C++中的自定义类
- 自定义派生的 std::exception 类的 'what' 函数返回神秘的废话
- 从 QAbstractItemModel 返回自定义用户类型
- 将 OpenGL 坐标系统转换为自定义并返回
- 基于范围的 for 循环,用于包含C++中的指针的自定义链表,仅返回对象
- C++ grpc::experimental:interceptor 如何从自定义拦截器返回状态和消息
- 是否可以为类设置自定义返回类型
- 具有自定义返回类型和"false"返回条件的函数?
- C :不同类型的模板功能(方法)的自定义返回值
- 在派生类中定义自定义返回类型的受保护方法
- 自定义返回类型声明
- 带有自定义返回值的seresult
- 具有自定义返回类型的全局命名空间中的友元函数