How is possible to deduce function argument type in C++?

前端 未结 5 611
南旧
南旧 2020-12-20 13:58

Having the function definition:

void f(int) { }

I want to define:

int a;

but if the function definition c

5条回答
  •  萌比男神i
    2020-12-20 14:18

    It depends on what you want to do, where that variable shall be used. If it is in the function a template might be a good choice:

    template
    void foo(T ) {
        T a;
    }
    

    Alternatively if you are outside the function and have the requirement to really know this you can use Boost.TypeTraits, i.e. function_traits::arg1_type will give int

提交回复
热议问题