Dynamic dispatching of template functions?

前端 未结 5 781
挽巷
挽巷 2020-12-10 14:02

Is it possible to decide in run-time which template function to call? Something like:

template
struct A {
    static void foo() {/*...*/}
};

vo         


        
5条回答
  •  Happy的楠姐
    2020-12-10 14:35

    Template argument must be known at compile time. So there is no way for compiler to pass A::foo().

    If you want work around then you have to make bar() also a template:

    template
    void bar() {
        A::f();   // ok
    }
    

    For that, you must know argument to bar() at compile time.

提交回复
热议问题