Answers

Question and Answer:

  Home  C++ Programmer

⟩ Tell us how to make sure a C++ function can be called as e.g. void foo(int, int) but not as any other type like void foo(long, long)?

Implement foo(int, int)…

void foo(int a, int b) {

// whatever

}

…and delete all others through a template:

template <typename T1, typename T2> void foo(T1 a, T2 b) = delete;

Or without the delete keyword:

template <class T, class U>

void f(T arg1, U arg2);

template <>

void f(int arg1, int arg2)

{

//...

}

 211 views

More Questions for you: