Q:

Explain the effect of the second declaration in each one of the following sets of declarations. Indicate which, if any, are illegal

0

 Explain the effect of the second declaration in each one of the following sets of declarations. Indicate which, if any, are illegal.

(a)

int calc(int&, int&);
int calc(const int&, const int&);

(b)

int calc(char*, char*);
int calc(const char*, const char*);

(c)

int calc(char*, char*);
int calc(char* const, char* const);

All Answers

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

(a)

 int calc(int&, int&);
 int calc(const int&, const int&);
 // OK, overloaded function takes reference to `const`

(b)

 int calc(char*, char*);
 int calc(const char*, const char*);
 // OK, overloaded function takes pointer to `const`

(c)

int calc(char*, char*);
 int calc(char* const, char* const);
 // Error, redeclare the same function, top-level `const` is ignored

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now