传递一个成员为vector的结构体
Pass a struct with a member being vector
我有一个类,它构建一个dll,作为一个单一的解决方案实现。在它的头文件中,我有一个结构体,其成员是vector。像以下;
// dll.h
struct ScanParam16
{
// int param
int nChanDetX, nChanDetZ;
int nViewPerRot, nViewPerSlice,
nChanDetXPerMod;
int nImgXY, nImgZ;
int nSlicePerProcess, n2Group;
int FFTLen;
// float param
float pitch;
float isoOffX, isoOffZ;
float fov, dfov;
float imgCentX, imgCentY, imgCentZ;
float sdd, srad, drad;
float dDetX, dDetZ, dDetU, dDetV, interModGapX, dDetSampleRes;
std::vector<float> winArray;
bool interleave;
// enum
bpInterpType16 iType;
};
在调用这个dll的代码中,向量winArrar的值如下:
// caller.cpp
static ScanParam16 param;
param.FFTLen = 2048;
float* wArray = new float[param.FFTLen];
GenKernCoef(wArray, param.FFTLen, kType, ParaDataFloat, aram.dDetSampleRes);
std::vector<float> v(wArray, wArray+param.FFTLen);
param.winArray = v;
现在一切看起来都很好。我可以看到param.winArray
被正确地设置为正确的值。
然而,当我传递param
作为参数时,param.winArray
在容量/长度上变为0,正如我在dll中观察到的。
参数是这样传递的:
//caller.cpp
ReconAxial16 operator;
operator.Init( param ) ;
上面是参数传递到dll之前的点。
下面是参数进入dll的点:
// dll.cpp
void ReconAxial16::Init(const ScanParam16& param )
{
/**************************************************************/
// setup geometry and detv
/**************************************************************/
SetupGeometry(param);
// Allocate buffer for reconstructed image (on cpu side)
_img = (float *)malloc(_nImgXY * _nImgXY * sizeof(float));
......
}
在这里,当我介入时,我可以看到param.winArray
的长度为0,但所有其他参数看起来都很好。
我不明白,我想知道如何正确传递向量?非常感谢。
我实际上没有这个问题的答案,但我只是展示了我是如何通过绕过它来实现我想要的。
我基本上是从结构体中剥离数组/向量,并将其作为第二个参数单独传递,类似于:
//caller.cpp
ReconAxial16 operator;
float* wArray = new float[param.FFTLen];
GenKernCoef(wArray, param.FFTLen, kType, ParaDataFloat, param.dDetSampleRes);
operator.Init( param, wArray ) ;
当然,在dll项目中,我做了这样的事情,使它接受数组作为附加参数:
// dll.h
LONG SetupGeometry( const ScanParam16 ¶m, float* wArray);
它工作。我介入,看到wArray
被正确地传递到dll中。
相关文章:
- 在C++中将类(带有Vector成员)保存为二进制文件
- 访问 std:vector 的类成员 std:vector 在一个类中与另一个 std:vector
- 有效地初始化 const std::vector 类成员
- 在设计方面:重载vector类型的类成员的插入运算符
- 使用静态 std::vector 类成员时出现访问冲突
- 不是 'std::vector<_Ty> 的成员
- 使用 vector.sort() 的非静态成员函数无效使用
- 将此类的智能指针追加到成员 std::vector
- 在Visual Studio中删除成员std::vector::d ata()
- Boost.interprocess Vector 作为类成员
- 为什么我的类 std::vector 成员总是抛出段错误?
- 使用<string>提升::序列化序列化具有 vector<unique_ptr> 成员的类
- 错误:"类 std::vector<Shape*>"没有名为"sort"的成员
- C 如何推动vector struct的成员
- 成员功能在面向对象的框架中返回std :: vector.size()的效率
- 如何将带有 std::vector 成员的类移动到<class>另一个向量<class>中?
- 动态内存分配与类私有成员C++的 std::vector
- 组织专用成员 Vector<Vector 接口的最佳方式<Type>>
- 初始化成员Vector值
- 具有自己成员的成员Vector的类