Google Mock Problem invoking overloaded method

8,470 views
Skip to first unread message

Valerio Provaggi

unread,
Dec 14, 2010, 5:59:36 AM12/14/10
to Google C++ Mocking Framework
Hi,
In my team we have a problem mocking an object. We have an interface
with a method overloaded, something like this:
class ITable {
public:
virtual void write(Record, Field, Value) = 0;
virtual void write(Record, Field, Position, Value)
= 0;
}

The mock has the two mock function definition witho MOCK_METHOD3 and
4. Usually we use to call the real object, like
ON_CALL(*this, write(_,_,_))
.WillByDefault(Invoke(mReal, &ITable::write));
Where mReal is a pointer to a concrete product object.

In the past when we had only a write with 3 all goes well, when we
introduced the 4 parameter version we had this compilation error:
"no matching function for call to Invoke <Unresolved overloaded
function type>"
Thank you very much,

Valerio

Vlad Losev

unread,
Dec 14, 2010, 6:09:11 AM12/14/10
to Valerio Provaggi, Google C++ Mocking Framework

harsha Vardhan

unread,
Mar 22, 2013, 2:43:11 AM3/22/13
to googl...@googlegroups.com
resolved the issue by using "static_cast" in ON_CALL function.
e.g : "For instance, if class Foo has methods char DoThis(int n) and bool DoThis(double x) const, and you want to invoke the latter, you need to write Invoke(&fake_, static_cast<bool (FakeFoo::*)(double) const>(&FakeFoo::DoThis)) instead of Invoke(&fake_, &FakeFoo::DoThis) (The strange-looking thing inside the angled brackets of static_cast is the type of a function pointer to the second DoThis() method.)."



On Thursday, March 21, 2013 3:07:54 PM UTC+5:30, harsha Vardhan wrote:
Even I'm facing same issue while writing a ON_CALL function for a overloaded function.

harsha Vardhan

unread,
Mar 22, 2013, 2:43:33 AM3/22/13
to googl...@googlegroups.com, Valerio Provaggi
resolved the issue by using "static_cast" in ON_CALL function.
e.g : "For instance, if class Foo has methods char DoThis(int n) and bool DoThis(double x) const, and you want to invoke the latter, you need to write Invoke(&fake_, static_cast<bool (FakeFoo::*)(double) const>(&FakeFoo::DoThis)) instead of Invoke(&fake_, &FakeFoo::DoThis) (The strange-looking thing inside the angled brackets of static_cast is the type of a function pointer to the second DoThis() method.)."


On Monday, February 18, 2013 8:07:04 PM UTC+5:30, Fermín Galán Márquez wrote:
Hi,

I'm facing a very similar problem. I have check the URL you point out, however I'm not sure if it helps in this case, as the URL tells how to select between overloaded functions for EXPECT_CALL, but it doesn't show any example using ON_CALL and Invoke.

Any help will be highly welcome. Thanks in advance!

Best regards,

------
Fermín
Reply all
Reply to author
Forward
0 new messages