C++构造函数代码在Windows上运行良好,但在MacOS上无法编译



以下是代码:

#include<iostream>
#include<string>
#include<vector>
enum class OrderBookType{bid, ask};
class OrderBookEntry{
public:
OrderBookEntry( double _price,
double _amount,
std::string _timeStamp,
std::string _product,
OrderBookType _orderType)
{
price = _price;
amount= _amount;
timeStamp= _timeStamp;
product= _product;
orderType= _orderType;
}
double price;
double amount;
std::string timeStamp;
std::string product;
OrderBookType orderType;
};
int main(){
OrderBookEntry order1{102000.01, 0.0001, "2020/03/17 17:01:24.884492", "ETH/BTC", OrderBookType::bid};
std::cout << "price: " << std::fixed << order1.price << std::endl;
return 0;
}

我得到的错误:

main.cpp:5:6: warning: scoped enumerations are a C++11 extension [-Wc++11-extensions]
enum class OrderBookType{bid, ask};
^
main.cpp:33:20: error: no matching constructor for initialization of 'OrderBookEntry'
OrderBookEntry order1{102000.01, 0.0001, "2020/03/17 17:01:24.884492", "ETH/BTC", OrderBookType::bid};
^
main.cpp:7:7: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 0 were provided
class OrderBookEntry{
^
main.cpp:10:9: note: candidate constructor not viable: requires 5 arguments, but 0 were provided
OrderBookEntry( double _price,
^
main.cpp:33:26: error: expected ';' at end of declaration
OrderBookEntry order1{102000.01, 0.0001, "2020/03/17 17:01:24.884492", "ETH/BTC", OrderBookType::bid};
^
;
1 warning and 2 errors generated.

正如编译器错误所示,只有从C++11开始才支持枚举类,因此在编译时,必须向C++编译器传递标志/开关或参数才能使用该版本的语言语法,然后只有它才会编译构造函数中传递的OrderBookType::bid最后一个参数。

相关内容

最新更新