[英]Pointer to std::vector, pointer declaration
这两个指针声明之间是否有任何区别,以便将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
(在这种情况下,是theVectorA
的第一个double
)。 因此p_VecA
是一个双精度指针数组,在这种情况下,如果您使用不带索引的名称,它会衰减到指向其第一个元素的指针(认为是double**
),而p_VecA[0]
的类型为double*
(例如p_VecB
是)。
double * p_VecB
创建一个指向double
的指针(在这种情况下,是theVectorB
的第一个double
)。
也许这可以帮助您了解libraryFunction()
的签名:
const int *,const int * const和int const *有什么区别?
就像杰克写道: arrayOfChannels
是指向const指针的指针
p_vecA是大小为1的指针数组
double * p_VecA[1];
p_VecB是指针
double * p_VecB = theVectorB.data();
可以写成
double * p_VecB;
p_VecB = theVectorB.data();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.