Q:

Figure out functions that cannot be overloaded in C++?

0

Figure out functions that cannot be overloaded in C++?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer:

Let see functions that can not be overloaded in C++.

1. Function declarations that differ only in the return type.

int fun()
{
    return 10;
}
char fun()
{
    return 'a';
}

2. Parameter declarations that differ only in a pointer * versus an array [] are equivalent.

int fun(int *ptr); 
int fun(int ptr[]);

3. Parameter declarations that differ only in that one is a function type and the other is a pointer to the same function type are equivalent.

void fun(int ()); 
void fun(int (*)());

4. Parameter declarations that differ only in the presence or absence of const and/or volatile are equivalent.

int f(int x)
{
    return x;
}
int f(const int x)
{
    return x;
}

5. Two parameter declarations that differ only in their default arguments are equivalent.

int f ( int x, int y)
{
    return x+10;
}
int f ( int x, int y = 10)
{
    return x+y;
}

6. Member function declarations with the same name and the name parameter-type list cannot be overloaded if any of them is a static member function declaration.

class Test
{
    static void fun(int i) {}
    void fun(int i) {}
};

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Interview Questions and Answers(2022)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
<< Name the Operators that cannot be Overloaded in c+...