首页 > 解决方案 > 枚举:不允许使用类型名称

问题描述

我是一名 .Net C# 程序员,试图用 C++ 编程。我有一个使用第三方库的应用程序。当我尝试在该库的函数中使用库中的 Enum 时,我收到类型不允许的错误消息:

我已经包括了图书馆:

#include <Trading.h>

using namespace Trading;

Trading.h 包括 Enumerations.h,其中包含:

/// Returns string representation.
FOO std::string enumToString (TimeInForce::Enum);

/// Trading session event type.
struct FOO TradSesEvent
{
    /// @copydoc TradSesEvent
    enum Enum
    {
       ...
    };
};

Application.cpp 的代码简化为问题:

#include <Trading.h>

using namespace Trading;

class Application
{
public:
    Application(const Settings& settings) : settings_(settings)
    {
        orderBook_.reset(new OrderBook());
    ...
    }

private:
    // Store of orders sent to counterparty.
    PtrTraits<OrderBook>::UniquePtr orderBook_;

    void onSendNewOrder(Order& newOrder)
    {
        //create unique_ptr to fill in the order values and sen

        PtrTraits<Order>::UniquePtr order(new Order(orderBook_->newId()));

        order->timeInForce = TimeInForce.Day;
        ...
    }
};

错误信息:

struct Application::TimeInForce type name is not allowedC/C++(254)

标签: c++

解决方案


命名在类或命名空间中声明的无范围枚举成员的语法TimeInForce是:

TimeInForce::Day

句点 ( .) 用于访问类的非静态成员。


推荐阅读