【发布时间】:2015-05-26 13:15:50
【问题描述】:
我有一个结构,其中结构内的结构为 显示在以下问题中: How to dynamically fill the structure which is a pointer to pointer of arrays in C++ implementing xfs
我需要将上述结构的值提取到我创建的另一个结构中。这个结构需要被视为结构数组。
typedef struct Sp_cashinfo
{
LPSTR lpPhysicalPositionName;
ULONG ulInitialCount;
ULONG ulCount;
}SP_CASHUNITINFO;
这个结构是一个结构数组,因为我需要以 2D 形式存储(即 7 次)
int CashUnitInfo(SP_CASHUNITINFO *Sp_cdm_cashinfo)
{
try
{
-----assigned the values----------------
hResult = WFSGetInfo (hService,dwCategory,lpQueryDetails,dwTimeOut,&lppResult); //assigned the values ,got the response 0 ie success
fwCashUnitInfo = (LPWFSCDMCUINFO)lppResult->lpBuffer;
USHORT NumPhysicalCUs;
USHORT count =(USHORT)fwCashUnitInfo->usCount;
Sp_cdm_cashinfo = (SP_CASHUNITINFO*)malloc(7*sizeof(SP_CASHUNITINFO));
for(int i=0;i<(int)count;i++)
{
NumPhysicalCUs =fwCashUnitInfo->lppList[i]->usNumPhysicalCUs;
for(int j=0;j<NumPhysicalCUs;j++)//storing the values of structure
{
Sp_cdm_cashinfo[i].lpPhysicalPositionName =fwCashUnitInfo->lppList[i]->lppPhysical[j]->lpPhysicalPositionName;
Sp_cdm_cashinfo[i].ulInitialCount =fwCashUnitInfo->lppList[i]->lppPhysical[j]->ulInitialCount;
}
}
return (int)hResult;
}
以上代码是写在类库中的,需要在类库中显示。
但是由于内存分配问题,我被困在我创建的结构中获取垃圾值。 我已经成功填充了主要结构((即)结构内的结构),我只需要这个结构中的特定成员
【问题讨论】:
-
有什么原因不能使用标准容器吗?
-
@shuttle87 : 什么是标准容器??
-
@shuttle87:所以你说要使用这些结构与 std::array 或 std::vector 对吗? .是的,我确实有问题,因为原始结构是预先定义的。因此我创建了一个用户定义的
-
@shuttle87:我遇到了内存问题,因为它没有正确地将数据存储在创建的结构中
标签: c++ arrays pointers structure cen-xfs