开发者

E2321 Declaration does not specify a tag or an identifier

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 synchron开发者_如何学Goizer
{
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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜