2011-01-19 2 views
1

VS2005에서 C++ Builder XE로 코드를 포팅하여 두 컴파일러에서 모두 컴파일합니다. 다음 코드는 VS2005에서 잘 컴파일되지만 C++ 빌더에서는 인라인 함수 rawtime()을 사용하여 주제 오류 메시지를받습니다.E2321 선언에서 태그 또는 식별자를 지정하지 않았습니다.

(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

생각/Commnets?

--- 편집 : TIMESTATS_STMT을 제안

피드백 그래서 여기 오류의 acutal 원인이 정의되는 방법이다. VS2005 및 C++ Builder XE에서는 TIME_ENABLE_STATISTICS가 주석으로 처리됩니다.

// #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을 undefining함으로써 정정 할 수 있었다. TIMESTATS_STMT는 말을 열심히에 확장,하지만 문제가 실제로 매크로 확장의 라인에 발생하고 나에게 잘 나타나는 다음 줄에 태그되고있는 걸 모르고

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

답변

1

.

+0

감사 마크, TIMESTATS_STMT 정의 된 방법에 대한 업데이트 된 게시물을 확인하십시오. 나는 TIMESTATS_STMT 라인을 주석 처리하고 많은 에러가 발생했다. 물론 (물론). – Eric

1

잘못된 : TIMESTATS_STMT(typedef statistics<counter_type> statistics_type);

올바른 : TIMESTATS_STMT(typedef statistics<counter_type> statistics_type)

매크로 후 세미콜론을 제거합니다. 매크로는 강력한 언어 확장이지만 때로는 매우 위험하고 예측할 수없는 경우도 있습니다.

나는 C++ 매크로를 사용하고 싶지만, 그들은 악합니다.

+0

수정 : C 매크로입니다. C++을 비난 할 필요는 없습니다. ;피 – leetNightshade