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 に答える