Error: cannot define 'enum class std::align_val_t' in different module
Error: cannot define 'enum class std::align_val_t' in different module
我是一名 C++ 初学者,正在寻找创建模块的机会。我遵循了几个指南并想用 类 测试模块。当我尝试通过 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
以下是文件,在此先感谢。
main.cpp
#include <iostream>
import airline_ticket;
int main()
{
std::cout << "Hello" << std::endl;
return 0;
}
func.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
module airline_ticket;
AirlineTicket::AirlineTicket()
{
// Initialize data members.
m_passengerName = "Unknown Passenger";
m_numberOfMiles = 0;
m_hasEliteSuperRewardsStatus = false;
}
func.cxx 中的 include 指令需要在全局模块片段区域中。否则你会得到重新定义。
即
module;
#include <string>
export module .....
...
我是一名 C++ 初学者,正在寻找创建模块的机会。我遵循了几个指南并想用 类 测试模块。当我尝试通过 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
以下是文件,在此先感谢。
main.cpp
#include <iostream>
import airline_ticket;
int main()
{
std::cout << "Hello" << std::endl;
return 0;
}
func.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
module airline_ticket;
AirlineTicket::AirlineTicket()
{
// Initialize data members.
m_passengerName = "Unknown Passenger";
m_numberOfMiles = 0;
m_hasEliteSuperRewardsStatus = false;
}
func.cxx 中的 include 指令需要在全局模块片段区域中。否则你会得到重新定义。
即
module;
#include <string>
export module .....
...