C++ Programmer Question:

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)?

Tweet Share WhatsApp

Answer:

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)
{
//...
}

Download C++ Programmer PDF Read All 59 C++ Programmer Questions
Previous QuestionNext Question
Tell me how can a C function be called in a C++ program?Explain me what will i and j equal after the code below is executed? Explain your answer.

int i = 5;
int j = i++;?