【问题标题】:E2321 Declaration does not specify a tag or an identifierE2321 声明未指定标签或标识符
【发布时间】:2011-01-19 14:37:54
【问题描述】:

我正在将代码从 VS2005 移植到 C++ Builder XE,以便它可以与两个编译器一起编译。以下代码在 VS2005 下编译良好,但在 C++ Builder 下,我收到带有内联函数 rawtime(); 的主题错误消息;

(E2321 声明未指定标签或标识符)。

代码如下:

template<typename counter_type>
class synchronizer
{
private:
// PRIVATE TYPES

typedef timer<counter_type>                     timer_type;
typedef reference_point<counter_type>           reference_point_type;
typedef time_data<counter_type>                 time_data;
typedef typename timer_type::time_stamp_type    time_stamp_type;
typedef typename timer_type::time_span_type     time_span_type;
typedef typename filetime_counter::value_type   time_type;
typedef typename counter_type::value_type       counter_value_type;
typedef synchronizer<counter_type>              this_type;

/* some code removed for sake of this post */

public:

typedef counter_type  counter_type;
typedef typename counter_type::value_type raw_value_type;
TIMESTATS_STMT(typedef statistics<counter_type> statistics_type);

inline raw_value_type rawtime() const   /* Subject ERROR coming from this line */
{
  return m_timer.now().value();
}

我尝试遵循这篇文章的结果,它解决了这个特定问题,但没有解决这个问题。 template class operator overloading problem

想法/通讯?

--- 编辑:

建议 TIMESTATS_STMT 是错误的真正原因的反馈,所以这里是如何定义的。注意 TIME_ENABLE_STATISTICS 在 VS2005 和 C++ Builder XE 中都被注释掉了。

// #define TIME_ENABLE_STATISTICS
//

//
// Make null definitions
//
#define TIMESTATS_VAR(var, type, initial)
#define TIMESTATS_STMT(stmt)

#ifdef TIME_ENABLE_STATISTICS

//
// Make real definitions
//
#undef  TIMESTATS_VAR
#define TIMESTATS_VAR(var, type, initial) type var = initial
#undef  TIMESTATS_STMT
#define TIMESTATS_STMT(stmt) stmt

--- 编辑

违规行似乎是 TIMESTATS_STMT 行。我可以通过取消定义 NULL #define 来纠正,如下所示。

#ifdef TIME_ENABLE_STATISTICS
  TIMESTATS_STMT(typedef statistics<counter_type> statistics_type);
#endif

【问题讨论】:

    标签: c++ function inline declaration


    【解决方案1】:

    错误:TIMESTATS_STMT(typedef statistics&lt;counter_type&gt; statistics_type);

    正确:TIMESTATS_STMT(typedef statistics&lt;counter_type&gt; statistics_type)

    删除宏后面的分号。宏是一种强大的语言扩展,但有时非常非常危险且不可预测。

    我喜欢使用 C++ 宏,但它们是邪恶的。

    【讨论】:

    • 更正:它们是 C 宏。您不必为此责怪 C++。 ;p
    【解决方案2】:

    在不知道 TIMESTATS_STMT 扩展为什么的情况下很难说,但我敢打赌,问题实际上发生在宏扩展行并被标记到下一行,这对我来说似乎很好。

    【讨论】:

    • 感谢 Mark,请参阅更新后的帖子了解如何定义 TIMESTATS_STMT。我尝试注释掉 TIMESTATS_STMT 行,但在其他地方(当然)出现了一系列错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-30
    • 1970-01-01
    • 1970-01-01
    • 2012-11-13
    • 2021-06-07
    相关资源
    最近更新 更多