我是 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
以下是檔案,在此先感謝。
主檔案
#include <iostream>
import airline_ticket;
int main()
{
std::cout << "Hello" << std::endl;
return 0;
}
函式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;
}
uj5u.com熱心網友回復:
func.cxx 中的 include 指令需要在全域模塊片段區域中。否則你會得到重新定義。
IE
module;
#include <string>
export module .....
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/429314.html
上一篇:如何在if陳述句中使用概念
下一篇:c std::vector<NotAPointer>如何存盤不同大小的物件,當它不包含指標時, it如何知道跳轉的位置
