简体   繁体   English

错误:无法在不同模块中定义“enum class std::align_val_t”

[英]Error: cannot define 'enum class std::align_val_t' in different module

I am a C ++ beginner and am looking to create a module.我是 C ++ 初学者,正在寻找创建模块的机会。 I have followed several guides and would like to test modules with classes.我遵循了几个指南,并想用类测试模块。 When I try to run the first module via g++-11 -c -std=c++20 -fmodules-ts func.cxx i get the following error:当我尝试通过g++-11 -c -std=c++20 -fmodules-ts func.cxx运行第一个模块时,出现以下错误:

In file included from /usr/local/Cellar/gcc/11.2.0_3/include/c++/11/bits/stl_iterator.h:82,
                 from /usr/local/Cellar/gcc/11.2.0_3/include/c++/11/bits/stl_algobase.h:67,
                 from /usr/local/Cellar/gcc/11.2.0_3/include/c++/11/bits/char_traits.h:39,
                 from /usr/local/Cellar/gcc/11.2.0_3/include/c++/11/string:40,
                 from func.cxx:2:
/usr/local/Cellar/gcc/11.2.0_3/include/c++/11/new:89:27: error: cannot define 'enum class std::align_val_t' in different module
   89 |   enum class align_val_t: size_t {};
      |                           ^~~~~~
<built-in>: note: declared here
/usr/local/Cellar/gcc/11.2.0_3/include/c++/11/new:89: confused by earlier errors, bailing out

Below are the files, thanks in advance.以下是文件,在此先感谢。

main.cpp主.cpp

#include <iostream>
import airline_ticket;


int main()
{
  std::cout << "Hello" << std::endl;
  return 0;
}

func.cxx函数.cxx

export module airline_ticket;
#include <string>

export class AirlineTicket
{

public:

AirlineTicket();
~AirlineTicket();

double calculatePriceInDollars(); std::string getPassengerName();

void setPassengerName(std::string name);

int getNumberOfMiles();
void setNumberOfMiles(int miles);

bool hasEliteSuperRewardsStatus();
void setHasEliteSuperRewardsStatus(bool status);

private:
std::string m_passengerName;
int m_numberOfMiles;
bool m_hasEliteSuperRewardsStatus;

};

func_impl.cxx func_impl.cxx

module airline_ticket;

AirlineTicket::AirlineTicket()
{
// Initialize data members.
m_passengerName = "Unknown Passenger";
m_numberOfMiles = 0;
m_hasEliteSuperRewardsStatus = false;
}

the include directive in func.cxx needs to be in the global module fragment area. func.cxx 中的 include 指令需要在全局模块片段区域中。 Else you'll get redefinitions.否则你会得到重新定义。

Ie IE

module;
#include <string>
export module .....
...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么`std :: align_val_t`应该限制隐式转换? - Why should `std::align_val_t` restrict implicit conversion? C ++分配器的std :: align_val_t有效的对齐值是什么? - What are the valid alignment values for std::align_val_t for C++ allocators? 为什么在使用 std::inplace_merge 时,英特尔的 C++ 2022 编译器出现“错误:对‘align_val_t’的引用不明确”? - Why do I get "error: reference to 'align_val_t' is ambiguous" with Intel's C++ 2022 compiler when using std::inplace_merge? 始终使用 operator new/delete 的 align_val_t 重载是否安全? - Is it safe to always use the align_val_t overload of operator new/delete? 为类模板的枚举成员定义std :: hash - Define std::hash for enum member of class template 在 C++ 中定义 class 枚举值的 std::vector 的缩写语法 - Abbreviated Syntax to define a std::vector of class enum values in C++ C++ 枚举类 std::size_t 隐式转换 - C++ enum class std::size_t implicit conversion 错误C2719:&#39;_ VAL&#39;:带__declspec(align(&#39;16&#39;))的形式参数将不对齐? - error C2719: '_Val': formal parameter with __declspec(align('16')) won't be aligned? 如何std ::地图 <enum class, std::string> ? - How to std::map<enum class, std::string>? boost.spirit编译错误:无法将参数1从“const char *”转换为“std :: _ St​​ring_iterator” <std::_String_val> - boost.spirit compilation error : cannot convert argument 1 from “const char * ” to "std::_String_iterator<std::_String_val>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM