gpt4 book ai didi

c++ - 如何创建指针来更新 C++ 中的动态 STL vector ?

转载 作者:行者123 更新时间:2023-11-30 03:09:52 25 4
gpt4 key购买 nike

我有一个动态数组,它将从不同的测试系统更新。我在语法方面遇到了困难。有人可以帮我吗?

这是我声明 vector 的地方

  void TestSystem::Drive(U32 RunMode, U32 Options)

{ //U32 is unsigned 32 bit



U32 condition;

U32 i;

U8 k;

vector<U32> badDriveList(1,0);//initial size of vector is 1 and value is 0

int *badDrivePointer[&badDriveList];



bool driveStatus = testSystems[k]->DriveCheck(badDrivePointer);//should this be &badDrivePointer?

// left side to "->" is correct. After that i am not sure

}

这是我更新 vector 的地方。

  int TestSystem::DriveCheck(int *badDriveList)

{

U32 condition;

U32 i= 10;

U32 j = 0;



for(j;j<i;j++)

{

badDriveList[j] = (*i)->shelf;//right hand side of this is working when tested with complete code base

//I am not sure how to write values in to badDriveList vector using pointers

}

}

这是我的 .h 文件的一部分

 int DriveCheck(int *);

最佳答案

您不能正确地使用指针 来更新STL 容器——相反,您需要使用迭代器insert_iterator尤其是适配器似乎正是您要找的东西。

关于c++ - 如何创建指针来更新 C++ 中的动态 STL vector ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3714099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com