C++ 以下代码是返回对堆栈对象的引用还是有效?

C++ 以下代码是返回对堆栈对象的引用还是有效?,c++,object,reference,return,stack,C++,Object,Reference,Return,Stack,我有一段代码,它从一个DLL调用当前进程中的一个函数,该DLL通过引用返回值。与我交谈的一个人说它是正确的,另一个人说它正在返回对堆栈对象的引用,这是未定义的行为。我不确定哪个人更实事求是,因为我没有他们中的任何一个经验 // Function call inside of the current process at a specific address. // Returns a matrix from the given meshcomponent and an id FMatrix*

我有一段代码,它从一个DLL调用当前进程中的一个函数,该DLL通过引用返回值。与我交谈的一个人说它是正确的,另一个人说它正在返回对堆栈对象的引用,这是未定义的行为。我不确定哪个人更实事求是,因为我没有他们中的任何一个经验

// Function call inside of the current process at a specific address. 
// Returns a matrix from the given meshcomponent and an id
FMatrix* GetMatrix(MeshComponent* mesh, FMatrix* result, int id) {
    return reinterpret_cast<FMatrix*(__fastcall*)(MeshComponent*, FMatrix*, int)>(address)(mesh, result, id);
}

// Gets the wanted 3D Vector out of the Matrix
void GetLocation(MeshComponent* mesh, FVector* result, int id) {
    FMatrix matrix;
    GetMatrix(mesh, &matrix, id);  <-- // When the function ends, is it possible for other stack operations to overwrite the matrix? Or is this valid?
    *result = static_cast<FVector>(matrix.WPlane);
}

// Usage, running from a DLL inside the process:
...
FVector location;
GetLocation(mesh, &location, id);
...
//当前进程内部特定地址的函数调用。
//从给定的meshcomponent和id返回矩阵
FMatrix*GetMatrix(MeshComponent*mesh,FMatrix*result,int id){
返回重新解释(地址)(网格、结果、id);
}
//从矩阵中获取所需的三维矢量
void GetLocation(网格组件*网格,FVector*结果,整数id){
FMatrix矩阵;

GetMatrix(网格和矩阵,id);根据您的评论


FVector只是包含{x,y,z}的3D向量的结构

此行数据复制到
result

*result = static_cast<FVector>(matrix.WPlane);

什么是
FVector
它是指针吗?我没有看到任何代码返回对堆栈对象的引用。通过调用
GetMatrix
您将指针作为参数传递给堆栈对象。FVector只是包含{x,y,z}的三维向量的结构.Meta-answer:让声称返回了对堆栈对象的引用的人指出堆栈对象和声称的对堆栈对象的引用。证明缺少某些内容要困难得多,举证责任应该由提出易于验证的声明的人承担。感谢您的回答:)
int& foo() {
    static int i;
    return i;
}