c++ - 获取指向 vector C++ 的指针

标签 c++ vector

这是我关于指针的第二个基本问题。 我正在调用 DLL 中公开的函数..

正在声明一个 vector ,并使用正在调用的函数内的值填充它。

我需要遍历 vector 并从调用函数访问它的值。

int calling_function()
{
int* vectorSize;
string input = "someValue";
vector<customObjects> *v;// do i need a pointer to a vector here?

void function_being_called(input,v,&vectorSize);

//need to access the vector here...

}

void function_being_called(string input, void *returnValue, int* vectorSize)
{
vector<customObjects> v;
v.push_back(myObj);

*vectorSize= v.size();

*returnValue = ? // how to pass vector to the calling function through this parameter pointer variable

return;
}

最佳答案

应该是这样的:

int calling_function()
{
  string input = "someValue";
  vector<customObjects> v;

  function_being_called(input,&v);

  // access the vector here...

}

void function_being_called(string input, vector<customObjects>* v)
{
  v->push_back(myObj);
}

关于c++ - 获取指向 vector C++ 的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26137757/

相关文章:

c++ - 我怎样才能卸载事件分区?

c++ - dup2 : write() redirected but not fprintf() or puts()

c++ - 一遍又一遍地构建相同的对象

c++ - 调用 C++ 容器的 size() 函数的运行时间是多少

c++ - 在 C++ 中返回一个 std::vector

vector - 无法理解本示例中点积的使用?

c++ - 字符串 vector 程序

c++ - 绑定(bind) std::function 错误

.net - native VC++ 6 应用程序中的托管 DLL

C++——子类析构函数是否应该显式调用基类析构函数?