我正在将代码从 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
最佳答案
错误:TIMESTATS_STMT(typedef statistics<counter_type> statistics_type);
正确:TIMESTATS_STMT(typedef statistics<counter_type> statistics_type)
删除宏后面的分号。宏是一种强大的语言扩展,但有时非常非常危险且不可预测。
我喜欢使用 C++ 宏,但它们很邪恶。
关于c++ - E2321 声明未指定标签或标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4736455/