这是我关于指针的第二个基本问题。 我正在调用 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/