Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google mock compile error (error: ‘<function name>’ is not a type)

Tags:

c++

googlemock

My actual code (class name changed, some cut, as it is company confidential, but there is only one compiler error, so what I cut should not be affecting things)

class Xyz
{
public:
   virtual void vPrintStatus() const;  
};

and its mock

class MockXyz : public Xyz
{
 public:
    MOCK_CONST_METHOD0(vPrintStatus,
            void());
};

Which gives me a compiler error : error: ‘vPrintStatus’ is not a type

#includes, etc are OK. The compiler is obviously finding vPrintStatus, as, if I change it to something undefined:

MOCK_CONST_METHOD0(independence,
                void());

I get error: ‘independence’ has not been declared.

So, the compiler finds vPrintStatus and appears to know its type (or, at least, what type it is not).

I am sure that I am following the syntax for MOCK_CONST_METHOD0 - the mock macro shoudl be expecting a function name, not a type, as its first parameter.

What am I doing wrong?

like image 934
Mawg says reinstate Monica Avatar asked Sep 16 '15 14:09

Mawg says reinstate Monica


Video Answer


1 Answers

The below error message:

error: ‘vPrintStatus’ is not a type

indicates that MOCK_CONST_METHOD0(vPrintStatus, void()); was parsed by a compiler as a declaration of a member function, named MOCK_CONST_METHOD0, taking two parameters, one of type vPrintStatus (hence the error), and another being a function pointer type (void(*)() after adjustment). Clearly, this means that the definition of macro MOCK_CONST_METHOD0 is not visible to the translation unit the mock declaration is part of. Make sure you have included <gmock/gmock.h> to that file.

like image 116
Piotr Skotnicki Avatar answered Oct 06 '22 05:10

Piotr Skotnicki