我想要一个包含几个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)
[ ]
答案 0 :(得分:0)
我发现这个有效:
#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 ]