我想要一个包含几个blitz++数组的结构。这个程序创建了这样一个结构,但是我不能正确地分配对象。是使用指向在结构之外分配的blitz++数组的指针来构造一个结构的唯一选择吗?
#include <iostream>
#include <blitz/array.h>
using namespace std;
using namespace blitz;
struct Bstruct{
Array<double,1> B;
};
int main(){
Bstruct str;
Array<double,1> x(10);
x = 1.0;
str.B = x;
cout << "x = " << x << endl;
cout << "str.B = " << str.B << endl;
return 0;
}
➜ blitz_struct git:(master) ✗ ./struct
x = (0,9)
[ 1 1 1 1 1 1 1 1 1 1 ]
str.B = (0,-1)
[ ]发布于 2016-07-13 14:18:36
我发现这个有用:
#include <iostream>
#include <blitz/array.h>
using namespace std;
using namespace blitz;
struct Bstruct{
Array<double,1> B;
};
int main(){
Bstruct str;
Array<double,1> x(10);
x = 1.0;
str.B.resize(10);
str.B = 1.0;
cout << "x = " << x << endl;
cout << "str.B = " << str.B << endl;
return 0;
}
➜ blitz_struct git:(master) ✗ ./struct
x = (0,9)
[ 1 1 1 1 1 1 1 1 1 1 ]
str.B = (0,9)
[ 1 1 1 1 1 1 1 1 1 1 ]https://stackoverflow.com/questions/38354106
复制相似问题