将 const double[][] 数组作为参数传递给 double** 接口
我有一个 2 维常量双矩阵,需要将其作为参数传递给采用(非常量)双**参数的函数。
[CEqParams.h] // < given as is - can't do a thing about it
class CEqParams
{
public:
void operator=(const CEqParams &right);
...
double dm_params[4][8];
};
。
[some_functions.h] // < dto.
...
void setEqParams(double **m);
...
。
[CEqParams.cpp]
void CEqParams::operator=(const CEqParams &right)
{
setEqParams( « magic here » );
}
其中« magic here »
(在代码片段的最后一段中)应采用right.dm_params
(或其内容的适当表示)。
除了手动将 right.dm_params
传输到辅助 double**
结构(通过运行在所有数组字段上的嵌套循环并逐一复制它们)然后还有什么其他方法吗?我可以在这里将后者传递给 setEqParams 吗?
PS:假设我能够将 right.dm_params
传递给采用 double[][]
(或 double[4][8 ]
?)作为参数 - 我如何摆脱 const
? “提示”:const_cast
不起作用。
I have a 2-dim const double matrix which needs to be passed as argument to a function that takes a (non-const) double** parameter.
[CEqParams.h] // < given as is - can't do a thing about it
class CEqParams
{
public:
void operator=(const CEqParams &right);
...
double dm_params[4][8];
};
.
[some_functions.h] // < dto.
...
void setEqParams(double **m);
...
.
[CEqParams.cpp]
void CEqParams::operator=(const CEqParams &right)
{
setEqParams( « magic here » );
}
where « magic here »
(in the final segment of code snippets) shall take right.dm_params
(or an appropriate representation of its contents, respectively).
What else than manually transferring right.dm_params
to an auxiliary double**
structure (by means of a nested loop running over all array fields and copying them one by one) and then passing the latter to setEqParams
could I do here?
PS: And given I'd be able to pass right.dm_params
to a function that takes a double[][]
(or double[4][8]
?) as parameter - how would I get rid of the const
? "Hint": A const_cast<double[4][8]>(right.dm_parameters)
doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种相当丑陋的方法,至少不需要复制所有数据,是创建一个行指针的临时数组,例如
One fairly ugly way, which at least doesn't require duplicating all the data, is to create a temporary array of row pointers, e.g.