编译gtest时报错

kerosun 2012-10-11 06:48:37
编译gtest时报告以下错误:
Invalid redefinition of 'InterceptMode'

源代码如下:

class GTEST_API_ ScopedFakeTestPartResultReporter
: public TestPartResultReporterInterface {
public:
// The two possible mocking modes of this object.
enum InterceptMode {
INTERCEPT_ONLY_CURRENT_THREAD, // Intercepts only thread local failures.
INTERCEPT_ALL_THREADS // Intercepts all failures.
};

// The c'tor sets this object as the test part result reporter used
// by Google Test. The 'result' parameter specifies where to report the
// results. This reporter will only catch failures generated in the current
// thread. DEPRECATED
explicit ScopedFakeTestPartResultReporter(TestPartResultArray* result);

// Same as above, but you can choose the interception scope of this object.
ScopedFakeTestPartResultReporter(InterceptMode intercept_mode, TestPartResultArray* result);

// The d'tor restores the previous test part result reporter.
virtual ~ScopedFakeTestPartResultReporter();

// Appends the TestPartResult object to the TestPartResultArray
// received in the constructor.
//
// This method is from the TestPartResultReporterInterface
// interface.
virtual void ReportTestPartResult(const TestPartResult& result);
private:
void Init();

const InterceptMode intercept_mode_;
TestPartResultReporterInterface* old_reporter_;
TestPartResultArray* const result_;

GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedFakeTestPartResultReporter);
};


把下面这个enum定义移到了类ScopedFakeTestPartResultReporter定义的外部,问题解决。
enum InterceptMode {
INTERCEPT_ONLY_CURRENT_THREAD, // Intercepts only thread local failures.
INTERCEPT_ALL_THREADS // Intercepts all failures.
};

我的理解是:
从类中的函数定义
ScopedFakeTestPartResultReporter(InterceptMode intercept_mode, TestPartResultArray* result);
看出参数InterceptMode应该是在类外部有定义的,因为这个函数是被外部调用的,传递给它的参数肯定应该事先定义。
所以在函数内部的enum定义就会报Invalid redefinition of 'InterceptMode'出错。

但是之前用其他版本的eclipse编译是没有问题的,不知道是什么原因这次编译却报错。
这次用的是最新的eclipse4.2,也许这次编译的选项不同。不知道是不是有开关会控制这个错误的检测。

请知道的兄弟帮忙解释一下。
...全文
206 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

64,647

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧