将 std::vector 传递给具有我不太了解的特殊签名的函数的这两个指针声明之间是否存在任何差异?
libraryFunction (int numSamples, double* const* arrayOfChannels) {
//things
}
std::vector<double> theVectorA = {11, 22, 33, 44};
double * p_VecA[1];
p_VecA[0] = theVectorA.data();
libraryFunction(theVectorA.size(), p_VecA);
std::vector<double> theVectorB = {55, 66, 77};
double * p_VecB = theVectorB.data();
libraryFunction(theVectorB.size(), p_VecB);
p_VecA 和 p_VecB 有什么区别?
你能解释一下函数签名吗?我不明白最后一部分。
最佳答案
double * p_VecA[1];
创建一个包含 1 个指针元素的数组,指向 double
(在这种情况下,第一个 double
在 theVectorA
)。因此p_VecA
是指向 double 的指针数组,在这种情况下,如果您使用不带索引的名称,它会衰减到指向其第一个元素的指针(将其视为 double**
)和 p_VecA[0]
类型为 double*
(就像 p_VecB
是)。
double * p_VecB
创建一个指向 double
的指针(在这种情况下,第一个 double
在 theVectorB
)。
更新:
也许这可以帮助您理解 libraryFunction()
的签名:
What is the difference between const int*, const int * const, and int const *?
就像 jack 写道:arrayOfChannels
是指向 double 的 const 指针
关于c++ - 指向 std::vector 的指针,指针声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47690527/