wq1129 2022-07-01 11:44 采纳率: 50%
浏览 258
已结题

static constexpr初始化数组遇到的问题

template<>
struct params {

typedef uint16_t value_type;
typedef int16_t signed_value_type;
typedef uint32_t greater_value_type;

typedef value_type* poly_t;

// The moduli used in each 16 bit block (14 bits long each)
// They are of the form p = 2*14 - i2*kMaxPolyDegree + 1 for increasing i
static constexpr unsigned int kMaxNbModuli = 2;
static constexpr value_type P[kMaxNbModuli] = { 15361U, 13313U};//有问题

// The associated lower word of their Newton quotients
static constexpr value_type Pn[kMaxNbModuli] = { 17458U, 60470U};//有问题

static constexpr unsigned int kModulusBitsize = 14;
static constexpr unsigned int kModulusRepresentationBitsize = 16;

// A primitive 2*kMaxNbModuli (i.e., 2**10) root of unity for each one of the moduli
static constexpr value_type primitive_roots[kMaxNbModuli] = { 4989U, 10076U};//有问题

// Inverses of kMaxPolyDegree (for the other degrees it can be derived easily)
// for the different moduli
static constexpr value_type invkMaxPolyDegree[kMaxNbModuli] = { 15331U, 13287U};//有问题

// Polynomial related data
static constexpr unsigned int kMaxPolyDegree = 512;
};

vs2015编译时遇到问题:
(代码中标注//有问题的语句都是下面形式的error,我把代码改成 static constexpr int P[2] = { 1,1};也是这样的error)
error C4579: 'nfl::params::P': in-class initialization for type 'const nfl::params::value_type [2]' is not yet implemented; static member will remain uninitialized at runtime but use in constant-expressions is supported
error C2131: 表达式的计算结果不是常数
note: 遇到非常量(子)表达式

  • 写回答

5条回答 默认 最新

  • 关注

    static 常量成员,除完全用于类内初始化的整型(kMaxNbModuli ),其余必须类内声明初始化,类外定义。

    
    #include <cstdint>
    
    struct params
    {
        using value_type = uint16_t;
        using signed_value_type = int16_t;
        using greater_value_type = uint32_t;
        using poly_t = value_type *;
    
        // The moduli used in each 16 bit block (14 bits long each)
        // They are of the form p = 2*14 - i2*kMaxPolyDegree + 1 for increasing i
        static constexpr unsigned int kMaxNbModuli = 2;
        static constexpr value_type P[kMaxNbModuli] = {15361U, 13313U};
    
        // The associated lower word of their Newton quotients
        static constexpr value_type Pn[kMaxNbModuli] = {17458U, 60470U};
        ;
    
        static constexpr unsigned int kModulusBitsize = 14;
        static constexpr unsigned int kModulusRepresentationBitsize = 16;
    
        // A primitive 2*kMaxNbModuli (i.e., 2**10) root of unity for each one of
        // the moduli
        static constexpr value_type primitive_roots[kMaxNbModuli] = {4989U, 10076U};
    
        // Inverses of kMaxPolyDegree (for the other degrees it can be derived
        // easily) for the different moduli
        static constexpr value_type invkMaxPolyDegree[kMaxNbModuli] = {15331U,
                                                                       13287U};
    
        // Polynomial related data
        static constexpr unsigned int kMaxPolyDegree = 512;
    };
    
    constexpr params::value_type params::P[kMaxNbModuli];
    constexpr params::value_type params::Pn[kMaxNbModuli];
    constexpr params::value_type params::primitive_roots[kMaxNbModuli];
    constexpr params::value_type params::invkMaxPolyDegree[kMaxNbModuli];
    
    int main()
    {
        params a;
        return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(4条)

报告相同问题?

问题事件

  • 系统已结题 7月12日
  • 已采纳回答 7月4日
  • 创建了问题 7月1日

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法