的std ::阵列&LT; T,N&GT;需要在另一类型的要获取 [英] std::array<T,N> need to be fetched in another types
问题描述
我有一个std ::阵列作为这样的成员变量类:
类my_class {
的std ::阵列&LT;点和LT;浮动&GT;,4是H.角落;
}
我需要这些角落
传递给许多功能。这些函数接受(点&LT; T&GT; * const的)
。所以,我简单地传递 corners.data()
。问题是,当一些功能可以接受特殊键入
在点
类的。例如,(点&LT;双&GT; * const的)
。我应该如何通过弯道与尽可能少的性能开销该功能。
code:
类my_class {
上市:
的std ::阵列&LT;点和LT;浮动&GT;,4是H.角落;
}
无效first_method(点&LT;浮动&GT; * const的输入);
无效second_method(点&LT;浮动&GT; * const的输入);诠释主(){
my_class富;
first_method(foo.corners.data()); // 好
second_method(foo.corners.data()); //问题
}
编辑:
我刚刚意识到,类无关我的问题,我们可以将其降低到
无效first_method(点&LT;浮动&GT; * const的输入);
无效second_method(点&LT;浮动&GT; * const的输入);诠释主(){
的std ::阵列&LT;点和LT;浮动&GT;,4是H.角落;
first_method(corners.data()); // 好
second_method(corners.data()); //问题
}
您不能。
您的数组是错误的类型,或函数有错误类型的参数。
请修复数组类型,或修复的功能,或者使第二阵列。
I have class which has a std::array as member variable like this:
class my_class{
std::array<point<float>,4> corners;
}
I need to pass these corners
to many functions. Those functions accept (point<T>* const)
. So, I simply pass corners.data()
. The Problem is when some function accept a special type
of the point
class. For example, (point<double>* const)
. How should I pass the corners to that function with the less possible performance overhead.
Code:
class my_class{
public:
std::array<point<float>,4> corners;
}
void first_method(point<float>* const input);
void second_method(point<float>* const input);
int main(){
my_class foo;
first_method(foo.corners.data()); // OK
second_method(foo.corners.data()); // Problem
}
EDIT:
I have just realized that the class has nothing to do with my problem we can reduce it to:
void first_method(point<float>* const input);
void second_method(point<float>* const input);
int main(){
std::array<point<float>,4> corners;
first_method(corners.data()); // OK
second_method(corners.data()); // Problem
}
You can't.
Your array is of the wrong type, or the functions have a parameter of the wrong type.
Either fix the array type, or fix the functions, or make a second array.
这篇关于的std ::阵列&LT; T,N&GT;需要在另一类型的要获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!