Friend function not defined in this scope

I've inherited some older code, that in the past has built, but is now failing,
and giving the error that friend functions are not defined in this scope,
I'm including excerpts from the code:

In the .h file:

// LibE Query class
// note this is an abstract class, the user must define queryCb
class eQuerier {
friend int _eQuerierCb(void*,const G2DESC*,void*);
protected:
virtual int queryCb(const G2DESC*,void*) = 0;
public:
const char *query(const char *exp) {
return eQuery(exp,_eQuerierCb,this);
};

};

Note eQuery is defined in a support library.

in the .C file:

int
_eQuerierCb(void* arg,const G2DESC* desc,void* msg)
{
return ((eQuerier*)arg)->queryCb(desc,msg);
}

g++ 4.8.2 command line:
g++ -D__cplusplus -D__STDCPP__ -D_SVID_SOURCE -I. -I../../include -Di386
-D__LinuxRH7 -c ooe.C


error:
In file included from ooe.C:4:0:
ooe.h: In member function const char* eQuerier::query(const char*):
ooe.h:110:21: error: _eQuerierCb was not declared in this scope
return eQuery(exp,_eQuerierCb,this);


Your help would really be appreciated.

Thanks

Mike Isaacs
Functions first introduced with a friend definition do not become visible to unqualified name lookup (except via ADL): http://en.cppreference.com/w/cpp/language/friend

Add a line
int _eQuerierCb(void*,const G2DESC*,void*);
just before class eQuerier {

Or, for a more typical approach, make sure it appears in the header file for that "support library", and #include that file before class _eQuerierCb is defined.
Last edited on
thanks, I placed prototypes in the top of the header and now it compiles properly.
Topic archived. No new replies allowed.