0

我想要一个包含几个 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)
[ ]
4

1 回答 1

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 ]
于 2016-07-13T14:18:36.537 回答