首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >结构中的Blitz++数组

结构中的Blitz++数组
EN

Stack Overflow用户
提问于 2016-07-13 14:11:45
回答 1查看 453关注 0票数 0

我想要一个包含几个blitz++数组的结构。这个程序创建了这样一个结构,但是我不能正确地分配对象。是使用指向在结构之外分配的blitz++数组的指针来构造一个结构的唯一选择吗?

代码语言:javascript
复制
#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)
[ ]
EN

回答 1

Stack Overflow用户

发布于 2016-07-13 14:18:36

我发现这个有用:

代码语言:javascript
复制
#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 ]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38354106

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档