[英]Pointer to std::vector, pointer declaration
Are there any differences between these two pointer declarations to pass a std::vector to a function that has a special signature that I don't really understand? 这两个指针声明之间是否有任何区别,以便将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);
What are the differences between p_VecA and p_VecB? p_VecA和p_VecB有什么区别?
Can you explain the function signature? 能解释一下功能签名吗? I don't understand the last part.
我不明白最后一部分。
double * p_VecA[1];
creates an array of 1 pointer element, which points to a double
(in this case, the first double
in theVectorA
). 创建一个由1个指针元素组成的数组,该数组指向一个
double
(在这种情况下,是theVectorA
的第一个double
)。 Therefore p_VecA
is an array of pointers to doubles, in this context if you use the name without index it decays to a pointer to its first element (think of it as double**
) and p_VecA[0]
is of type double*
(like p_VecB
is). 因此
p_VecA
是一个双精度指针数组,在这种情况下,如果您使用不带索引的名称,它会衰减到指向其第一个元素的指针(认为是double**
),而p_VecA[0]
的类型为double*
(例如p_VecB
是)。
double * p_VecB
creates a pointer to a double
(in this case, the first double
in theVectorB
). double * p_VecB
创建一个指向double
的指针(在这种情况下,是theVectorB
的第一个double
)。
Maybe this can help you to understand the signature of libraryFunction()
: 也许这可以帮助您了解
libraryFunction()
的签名:
What is the difference between const int*, const int * const, and int const *? const int *,const int * const和int const *有什么区别?
Like Jack wrote: arrayOfChannels
is a pointer to a const pointer to double 就像杰克写道:
arrayOfChannels
是指向const指针的指针
p_vecA is an array of pointers with size 1 p_vecA是大小为1的指针数组
double * p_VecA[1];
p_VecB is pointer p_VecB是指针
double * p_VecB = theVectorB.data();
Can be written as 可以写成
double * p_VecB;
p_VecB = theVectorB.data();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.