You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Explain the effect of the second declaration in each one of the following sets of declarations. Indicate which, if any, are illegal.
(C) int calc(char*, char*); int calc(char* const, char* const);
Question or Bug
Answer is "illegal" in https://github.com/pezy/CppPrimer/blob/master/ch06/README.md#exercise-653 .
But I think the second one is a legal redeclaration. Compiler treats them as one function. It will not make any warning as long as they don't have their own definitions which will trigger a redefinition error.
int calc(char*, char*);
int calc(char* const a, char* const b) {
cout << a << b << endl;
}
int main() {
char s1[] = "Hello", s2[] = "World";
calc(s1, s2);
return 0;
}
The text was updated successfully, but these errors were encountered:
Exercise information
Exercise 6.53
Question or Bug
Answer is "illegal" in https://github.com/pezy/CppPrimer/blob/master/ch06/README.md#exercise-653 .
But I think the second one is a legal redeclaration. Compiler treats them as one function. It will not make any warning as long as they don't have their own definitions which will trigger a redefinition error.
Your enviroment information
Tested on an online compiler.
https://www.onlinegdb.com/online_c++_compiler
The text was updated successfully, but these errors were encountered: