簡體   English   中英

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是什么,盡管事實上它是在函數之前聲明的?

您定義了一個結構DeltaKinematics::workingPoint ,然后嘗試返回一個結構workingPoint 您需要明確的資格。

這只是查找的問題。 您需要完全限定名稱,例如
vector<DeltaKinematics::workingPoint> DeltaKinematics::calculateWorkingPointCloud(){...

在這里問了一個關於這個問題的類似問題。 也許它對你來說也很有趣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM