Given the following code:
template <class Func>
void f(Func func , int* param){
func(/* how can I send "param" as const "int*" */);
}
How can I do it so that if f
don't get the variable as const - so we will get error ?
Given the following code:
template <class Func>
void f(Func func , int* param){
func(/* how can I send "param" as const "int*" */);
}
How can I do it so that if f
don't get the variable as const - so we will get error ?
If you want to make sure that f
accepts a pointer to const-qualified int you can cast function argument appropriately:
f(static_cast<int const *>(param));
Alternatively, if you want to make sure that f
accepts a reference to const-qualified pointer you can add const qualifier to function argument:
void f(Func f , int * const param)