Jon*_*han 9 c++ overloading mocking visual-c++ googlemock
我正在嘲笑一个使用Google Mock和VS2010的2个重载函数的C++类:
#include "stdafx.h"
#include "gmock/gmock.h"
#include "A.h"
class MockA : public A
{
public:
// ...
MOCK_METHOD3(myFunc, void(const int id, const int errorCode, const CString errorMsg));
MOCK_METHOD1(myFunc, void(const CString errorMsg));
// ...
};
Run Code Online (Sandbox Code Playgroud)
每次编译我都会收到两次以下警告:
1>c:\dev\my_project\tests\mocka.h(83): warning C4373: 'MockA::myFunc': virtual function overrides 'A::myFunc', previous versions of the compiler did not override when parameters only differed by const/volatile qualifiers
1> c:\dev\my_project\my_project\include\a.h(107) : see declaration of 'A::myFunc'
Run Code Online (Sandbox Code Playgroud)
知道为什么吗?
这是正确的行为吗?
我怎么能避免这个?
对我来说(在 VS 2010 中),指定const原始类型参数(我看到你也有)导致了这种行为。每当我想覆盖的基类函数中存在此类时,我都无法以某种方式指定模拟,以免发生此警告;当只有类类型 const value / const 引用参数时,警告从未发生。
所以在我看来,这种情况下的警告实际上是编译器中的一个错误(因为签名完全相同)。