Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
区分指向C+中重载成员函数的指针+; 我想区分C++模板结构中的重载成员函数。如果此方法存在,则静态方法get\u pointerfrom specialized structdistribute\u foo应返回指向derived::fo_C++_Templates_Member Function Pointers_Typetraits - Fatal编程技术网

区分指向C+中重载成员函数的指针+; 我想区分C++模板结构中的重载成员函数。如果此方法存在,则静态方法get\u pointerfrom specialized structdistribute\u foo应返回指向derived::fo

区分指向C+中重载成员函数的指针+; 我想区分C++模板结构中的重载成员函数。如果此方法存在,则静态方法get\u pointerfrom specialized structdistribute\u foo应返回指向derived::fo,c++,templates,member-function-pointers,typetraits,C++,Templates,Member Function Pointers,Typetraits,区分指向C+中重载成员函数的指针+; 我想区分C++模板结构中的重载成员函数。如果此方法存在,则静态方法get\u pointerfrom specialized structdistribute\u foo应返回指向derived::foo的指针。否则,我想返回一个指向pseudo::foo的指针 我怎样才能做到这一点 struct sample { void foo() { std::cout << "void sample::f

区分指向C+中重载成员函数的指针+; <>我想区分C++模板结构中的重载成员函数。如果此方法存在,则静态方法
get\u pointer
from specialized struct
distribute\u foo
应返回指向
derived::foo
的指针。否则,我想返回一个指向
pseudo::foo
的指针
我怎样才能做到这一点

struct sample
{
    void foo()              { std::cout << "void sample::foo()" << std::endl; }
    void foo(int)           { std::cout << "void sample::foo(int)" << std::endl; }
    void foo(int, int)      { std::cout << "void sample::foo(int, int)" << std::endl; }
    void foo(int, int, int) { std::cout << "void sample::foo(int, int, int)" << std::endl; }
};

struct other
{
    void foo()              { std::cout << "void other::foo()" << std::endl; }
    void foo(int)           { std::cout << "void other::foo(int)" << std::endl; }
    void foo(int, int)      { std::cout << "void other::foo(int, int)" << std::endl; }
    void foo(int, int, int) { std::cout << "void other::foo(int, int, int)" << std::endl; }
};

struct derived : sample, other
{
    using sample::foo;
    using other::foo;
};


template<typename signature>
struct distinguish_foo;

template<class C, typename R>
struct distinguish_foo<R (C::*)()>
{
    typedef char(&unique)[0xffff];
    struct pseudo { unique foo(); };
    struct host : C, pseudo {};

    template<typename R>
    static R (host::*get_pointer())() { return &host::foo; }
};

template<class C, typename R, typename P0>
struct distinguish_foo<R (C::*)(P0)>
{
    typedef char(&unique)[0xffff];
    struct pseudo { unique foo(P0); };
    struct host : C, pseudo {};

    template<typename R>
    static R (host::*get_pointer())(P0) { return &host::foo; }
};

template<class C, typename R, typename P0, typename P1>
struct distinguish_foo<R (C::*)(P0, P1)>
{
    typedef char(&unique)[0xffff];
    struct pseudo { unique foo(P0, P1); };
    struct host : C, pseudo {};

    template<typename R>
    static R (host::*get_pointer())(P0, P1) { return &host::foo; }
};

template<class C, typename R, typename P0, typename P1, typename P2>
struct distinguish_foo<R (C::*)(P0, P1, P2)>
{
    typedef char(&unique)[0xffff];
    struct pseudo { unique foo(P0, P1, P2); };
    struct host : C, pseudo {};

    template<typename R>
    static R (host::*get_pointer())(P0, P1, P2) { return &host::foo; }
};
struct示例
{

void foo(){std::cout你认为你为什么要这样做?我试图更详细地描述我的问题来实现这一点:你会对结果做什么?不可能用
派生的
对象来调用它。@n.m.以及其他可能的对象。请注意,原来的问题已经存在5年多了,是由编辑挖掘出来的。它看起来是q根据具体情况,它可能已经过时。不过OP似乎仍处于活动状态。