gpt4 book ai didi

c++ - 错误 : initialization with '{...}' is not allowed for object of type "const MyClass"

转载 作者:行者123 更新时间:2023-11-30 02:54:04 25 4
gpt4 key购买 nike

基本上我有一个 SIMD 结构的包装器,如下所示:

class MyClass
{
public:
MyClass();

__m128 SIMD;
};

我看到在 Microsoft 的 DirectXMath SIMD 数学库中,它们可以执行以下操作:

const XMVECTOR SinCoefficients0    = {-0.16666667f, +0.0083333310f, -0.00019840874f, +2.7525562e-06f};

XMVECTOR 只是围绕着这样的东西:

union
{
float f[4];
__m128 entry;
};

我也尝试过对数组使用 union ,但它仍然给我同样的错误。

最佳答案

为了能够使用聚合初始化,您需要删除用户定义的构造函数并确保所有成员都是公共(public)的:

struct MyClass
{
__m128 SIMD;
};

请阅读aggregate initialization其中解释了聚合是什么以及初始化的工作原理。

关于c++ - 错误 : initialization with '{...}' is not allowed for object of type "const MyClass",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17385049/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com