delegates icon indicating copy to clipboard operation
delegates copied to clipboard

Duplicate code

Open mfeemster opened this issue 10 years ago • 0 comments

The code for const function delegates causes a compilation error in VC++ 2013:

template<typename return_type, typename... params>
class Delegate<return_type(params...) const>
        : public BaseDelegate<return_type, params...>
{
    typedef BaseDelegate<return_type, params...> Base;
public:
    Delegate(void* callee, typename Base::Pointer2Function function)
        : Base(callee, function)
    { }
};

error C2953: 'Delegate<return_type(params...),>' : class template has already been defined.

Which also causes an error further down in the file:

    template<return_type(T::*Func)(params...) const>
    inline static Delegate<return_type(params...) const> CreateC(T* o)
    {
        return Delegate<return_type(params...) const>(o, &DelegateFactory::MethodCallerC<Func>);
    }

'abstract declarator' : modifiers not allowed on nonmember functions

Here is what is needed for it to fully build:

#ifndef _MSC_VER
template<typename return_type, typename... params>
class Delegate<return_type(params...) const>
        : public BaseDelegate<return_type, params...>
{
    typedef BaseDelegate<return_type, params...> Base;
public:
    Delegate(void* callee, typename Base::Pointer2Function function)
        : Base(callee, function)
    { }
};
#endif

...

#ifdef _MSC_VER
    template<return_type(T::*Func)(params...) const>
    inline static Delegate<return_type(params...)/* const*/> CreateC(T* o)
    {
        return Delegate<return_type(params...)/* const*/>(o, &DelegateFactory::MethodCallerC<Func>);
    }
#else
    template<return_type(T::*Func)(params...) const>
    inline static Delegate<return_type(params...) const> CreateC(T* o)
    {
        return Delegate<return_type(params...) const>(o, &DelegateFactory::MethodCallerC<Func>);
    }
#endif

Were you able to get this to build in Visual C++?

Thanks.

mfeemster avatar Jun 18 '15 22:06 mfeemster