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)
[ ]

1 ответ

Я нашел это на работу:

#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 ]
Другие вопросы по тегам