What is the difference between the following two declarations:
1. int foo(int);
2. int foo(int());
I am not sure if both the declarations are equivalent. What makes (2)
different from (1)
?
You can resolve ambiguity by qualifying a member with its class name using the scope resolution ( :: ) operator. The statement dptr->j = 10 is ambiguous because the name j appears both in B1 and B2 .
Access to a base class member is ambiguous if you use a name or qualified name that does not refer to a unique function or object. The declaration of a member with an ambiguous name in a derived class is not an error. The ambiguity is only flagged as an error if you use the ambiguous member name.
int foo(int);
is the declaration of a function taking an integer as an argument and returning an integer as well
int foo(int());
declares a function taking as an argument "a pointer to a function returning int
and taking {no arguments[in C++] and unspecified number of arguments[in C]} " and returning an integer.
(2)
is equivalent to int foo(int (*pf)())
and int foo(int f())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With