Why member functions can't be used as template arguments?

前端 未结 2 1758
小蘑菇
小蘑菇 2021-01-04 18:59

Why member functions cannot be used as template arguments? For example, I want to do like:

struct Foo {
    void Bar() { // do something
    }
};
template &         


        
2条回答
  •  长情又很酷
    2021-01-04 19:22

    They can be used as non-type parameters, but you need to use the right syntax

    struct Foo {
        void Bar() { // do something
        }
    };
    template 
    void Call(TOwner *p) {
        (p->*func)();
    }
    int main() {
        Foo a;
        Call(&a);
        return 0;
    }
    

提交回复
热议问题