E2321 声明未指定标签或标识符

发布于 2024-10-12 23:20:11 字数 2033 浏览 4 评论 0原文

我将代码从 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();
}

我尝试按照这篇文章的结果解决该特定问题,但没有解决这个问题。 模板类运算符重载问题

想法/通讯?

--- 编辑:

反馈表明 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

I'm porting code from VS2005 to C++ Builder XE so that it will compile with both compilers. The following code compiles fine under VS2005 but under C++ Builder I get the subject error message with the inline function rawtime();

(E2321 Declaration does not specify a tag or an identifier).

Here is the code:

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();
}

I tried following the results from this post which solved that particular problem but not this one.
template class operator overloading problem

Thoughts/Commnets?

--- EDIT:

Feedback suggesting the TIMESTATS_STMT is acutal cause of the error so here is how that is defined. Note that TIME_ENABLE_STATISTICS is commented out in both VS2005 and 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

--- EDIT

offending line does appear to be the TIMESTATS_STMT line. I was able to correct by undefining NULL #define as follows.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷清清 2024-10-19 23:20:11

错误:TIMESTATS_STMT(typedef statsstatistics_type);

正确:TIMESTATS_STMT(typedef statsstatistics_type)

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

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

Wrong: TIMESTATS_STMT(typedef statistics<counter_type> statistics_type);

Correct: TIMESTATS_STMT(typedef statistics<counter_type> statistics_type)

Remove the semicolon after the macro. The macro is a powerful language extension, but sometimes very-very dangerous and unpredictable.

I like to use C++ macros, but they are evil.

堇年纸鸢 2024-10-19 23:20:11

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

Without knowing what TIMESTATS_STMT expands to it's hard to say, but I bet the problem actually occurs on the line of the macro expansion and is being tagged to the following line, which appears fine to me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文