为什么这次闪电战不发生? 代码编译?
我是 blitz++ 新手。 到目前为止,一切都很好,但我有点困惑为什么下面代码中的注释行无法
error: conversion from ‘blitz::_bz_tinyMatExpr<blitz::_bz_tinyMatrixMatrixProduct<double, double, 3, 3, 3, 3, 1, 3, 1> >’ to non-scalar type ‘const m33’ requested
在 Debian/Lenny(g++ 4.3.2,Blitz 0.9)上编译。 这是代码:
#include <blitz/blitz.h>
#include <blitz/array.h>
#include <blitz/matrix.h>
#include <blitz/matexpr.h>
#include <blitz/tinymat.h>
#include <blitz/tinymatexpr.h>
#include <blitz/tinyvec.h>
#include <blitz/tinyvec-et.h>
#include <blitz/vector.h>
#include <blitz/vector-et.h>
typedef blitz::TinyVector<double,3> v3;
typedef blitz::TinyMatrix<double,3,3> m33;
int main(int,char**)
{
const m33 a;
const m33 b;
m33 c;c=blitz::product(a,b); // Compiles OK
//const m33 d=blitz::product(a,b); // Fails to compile.
return 0;
}
我确实喜欢完全 const-ed,所以很高兴知道是否有办法让它工作(到目前为止 Blitz++ 的经验表明这可能只是选择正确的问题)包括...)。
I'm a blitz++ newbie. So far, so good, but I'm a bit mystified why the commented out line in the code below fails to compile with
error: conversion from ‘blitz::_bz_tinyMatExpr<blitz::_bz_tinyMatrixMatrixProduct<double, double, 3, 3, 3, 3, 1, 3, 1> >’ to non-scalar type ‘const m33’ requested
I'm on Debian/Lenny (g++ 4.3.2, Blitz 0.9).
Here's the code:
#include <blitz/blitz.h>
#include <blitz/array.h>
#include <blitz/matrix.h>
#include <blitz/matexpr.h>
#include <blitz/tinymat.h>
#include <blitz/tinymatexpr.h>
#include <blitz/tinyvec.h>
#include <blitz/tinyvec-et.h>
#include <blitz/vector.h>
#include <blitz/vector-et.h>
typedef blitz::TinyVector<double,3> v3;
typedef blitz::TinyMatrix<double,3,3> m33;
int main(int,char**)
{
const m33 a;
const m33 b;
m33 c;c=blitz::product(a,b); // Compiles OK
//const m33 d=blitz::product(a,b); // Fails to compile.
return 0;
}
I do like to be const-ed to the hilt, so it'd be nice to know if there's a way of getting it to work (experience with Blitz++ so far suggests it might just be a matter of picking the right includes...).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我看过 Blitz++ 的源代码。
看起来令人惊讶的是,TinyMatrix 没有模板构造函数,但有一个 template = 运算符。
这意味着你无法做你想做的事。 所以我建议忘记你的矩阵是 const 。 或者找到另一种方法,例如创建一个非常量矩阵,将其作为常量引用作为函数的参数传递。
现在,只是为了好玩,事实是您可以复制模板operator=() 代码并在blitz/tinymat.h 中创建一个新的模板构造函数,但我不会! 如果您真的想要,请按照以下方式进行:
以及您的代码的编译(并且可能有效)。
I have had a look at the source code of Blitz++.
As surprising as it may seem, there is no template constructor for TinyMatrix, but there is a template = operator.
That means that you cannot do what you are trying to do. So I'd suggest forgetting about your matrix being const. Or find another way like creating a non-const matrix that you would pass as a const reference as the parameter of a function.
Now, just for fun, the truth is you could copy template operator=() code and make a new template constructor inside blitz/tinymat.h out of it, but i wouldn't ! If you really want to, here's how :
and your code compiles (and probably works).
抱歉,我不知道闪电战,但一些想法可能会有所帮助。
blitz::TinyMatrix 是否有合适的构造函数?
也许尝试其他形式的复制构造函数
应用标准 const 关键字真的合适吗? 也许你可能需要
sorry don't know blitz, but some ideas that might help.
Does the blitz::TinyMatrix have appropriate constructors?
Perhaps try the other form of copy constructor
Is applying the standard const keyword really appropriate? Perhaps you might need