Dynamic dispatching of template functions?

前端 未结 5 779
挽巷
挽巷 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条回答
  •  抹茶落季
    2020-12-10 14:28

    No, templates are a compile-time feature, and i is not known at compile-time so this is impossible. A::foo() should be adapted to something like A::foo(i).

提交回复
热议问题