开发者

GMock and mocking constructors in a class with non virtual methods

i need to mock a class that has only non virtual methods. This 开发者_StackOverflow中文版class has a copy constructor. How to I write a mock method for that. I get a compiler error if I just use the

MOCK_METHOD1(classname, void(classname& source)); 

Thanks in advance.


You can't mock non-virtual functions with gmock. So the first alternative to consider is to make the functions virtual. If you are concerned with performance overhead of making the functions virtual make sure that this really is a problem (by measuring), cause generally it ain't.

An alternative solution if there is no possibility to make the functions virtual is to use templates. See this question for details on this technique and this question for pros and cons of using it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜