Skip to content

Duplicate code #2

Description

@mfeemster

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions