vendredi 25 août 2017

Template Proxy Method Won't Compile

I'm having trouble getting the following code to compile.

template<typename W, typename I, typename B>
class ConcreteInterfaceWrapper
{
protected:
    template<typename... Args, void (W::*Functor)( Args... )>
    static void proxyCall( void* object, Args... args ) { (static_cast<W*>( object )->Functor)( args... ); }
{

class Plugin: public ConcreteInterfaceWrapper<Plugin, IPlugin, IPluginBase>
{
public:
    void tearDown() {}
    void somethingOther() { proxyCall<&tearDown>( nullptr ); }
}

Basically I'm trying to implement a generic proxy function that will let me call members of the derived class. I'm using the proxy function to plug into function pointers for a C struct so the signature of proxyCall can't be changed. The alternative is to make a proxy function for every method such as void proxyInitialize( void* object ) { static_cast<Derived1*>( object )->initialize(); }

I'm running into the problem of my compiler (g++) complaining that there is no matching function for proxyCall and I get two notes which are useless:

note: candidate: template<class ... Args, void (Plugin::* Functor)(Args ...)> static void ConcreteInterfaceWrapper<W, I, B>::proxyCall(void*, Args ...) [with Args = {Args ...}; void (W::* Functor)(Args ...) = Functor; W = Plugin; I = IPlugin; B = IPluginBase]
  static void proxyCall( void*, Args... );

note:   template argument deduction/substitution failed:

Aucun commentaire:

Enregistrer un commentaire