Callbacks in C++

  • Thread starter =?windows-1252?Q?=8Aimon_T=F3th?=
  • Start date
O

Old Wolf

©imon Tóth said:
Line 460:

CBFunctionTranslator0wRet(Func
f):CBFunctor0wRet said:
I didn't post the error in my first post, because I was searching for a
newer version of the callback.h file. This one is from 1996. And editing
this file seems very hardcore to me :)

Ah, sussed it now, please disregard my previous reply :)
The problem is with two-phase lookup. Here is a minimal
program that reproduces the problem:

struct Base
{
typedef void (*PFunc)();
};

void bar();

template<typename T>
struct Derived: T
{
void foo() { (Func)bar; }
};

The problem is that according to ISO C++, the compiler does
NOT look in template-dependent base classes when it's looking
up a name like 'PFunc'. So it thinks PFunc is an undefined symbol
unless you specifically say that it has come from a base class.

So, one way to solve this is to replace 'PFunc' with
'CBFunctorBase::pFunc', wherever you are getting the error.
Note, you do not use the 'typename' keyword because once you have
specified 'Base::pFunc', and Base is NOT a template, the compiler
knows what PFunc is.

I tried adding 'using Base::pFunc;' to Derived, as that is how
you could solve the problem if it was an object we were looking
up, but it actually didn't solve the problem. Maybe someone else
can make another suggestion, now that the problem is clearer?
 
O

Old Wolf

©imon Tóth said:
Line 460:

CBFunctionTranslator0wRet(Func
f):CBFunctor0wRet said:
I didn't post the error in my first post, because I was searching for a
newer version of the callback.h file. This one is from 1996. And editing
this file seems very hardcore to me :)

Ah, sussed it now, please disregard my previous reply :)
The problem is with two-phase lookup. Here is a minimal
program that reproduces the problem:

struct Base
{
typedef void (*PFunc)();
};

void bar();

template<typename T>
struct Derived: T
{
void foo() { (Func)bar; }
};

The problem is that according to ISO C++, the compiler does
NOT look in template-dependent base classes when it's looking
up a name like 'PFunc'. So it thinks PFunc is an undefined symbol
unless you specifically say that it has come from a base class.

So, one way to solve this is to replace 'PFunc' with
'CBFunctorBase::pFunc', wherever you are getting the error.
Note, you do not use the 'typename' keyword because once you have
specified 'Base::pFunc', and Base is NOT a template, the compiler
knows what PFunc is.

I tried adding 'using Base::pFunc;' to Derived, as that is how
you could solve the problem if it was an object we were looking
up, but it actually didn't solve the problem. Maybe someone else
can make another suggestion, now that the problem is clearer?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top