C++20 模块 - 无法导出 const 和 constexpr

问题描述 投票:0回答:0

我尝试在 GCC 编译器中为 STM32 微控制器使用 C++20 模块。我面临的问题是我无法导出模块中声明的任何常量或 constexpr:

sys_defs 模块:

export module sys_defs;
export const int abc = 0;

main.cpp:

import sys_defs;

void main()
{
   if (abc == 0)                  // compiler error: error: 'abc' was not declared in this scope
   {
       // do some stuff here
   }
}

我做错了什么?

当我导出常规函数、类等时,它工作正常。但是我在尝试导出常量和 constexpr 时总是出错。

c++ constants c++20 constexpr c++-modules
© www.soinside.com 2019 - 2024. All rights reserved.