S
subramanian100in
This question is for learning purpose only.
Consider the program x.cpp:
#include <cstdlib>
using namespace std;
void fn(int x = 7);
void fn(int = 7);
int main()
{
return EXIT_SUCCESS;
}
When I compiled this program with g++3.4.3 as
g++ -std=c++98 -pedantic -Wall -Wextra x.cpp,
I get the following compilation error:
x.cpp:6: error: default argument given for parameter 1 of `void fn
(int)'
x.cpp:5: error: after previous specification in `void fn(int)'
But Stroustrup in his book "The C++ Programming Language - Third
Edition(NOT the Special Third Edition)" has mentioned the following in
page 153 in section "7.5 Default Arguments":
A default argument can be repeated in a susequent declaration in the
same scope but not changed. Having this being stated, I do not
understand why the compiler is giving error. Have I misunderstood what
Sttroustrup has stated ? Kindly clarify.
Thanks
V.Subramanian
Consider the program x.cpp:
#include <cstdlib>
using namespace std;
void fn(int x = 7);
void fn(int = 7);
int main()
{
return EXIT_SUCCESS;
}
When I compiled this program with g++3.4.3 as
g++ -std=c++98 -pedantic -Wall -Wextra x.cpp,
I get the following compilation error:
x.cpp:6: error: default argument given for parameter 1 of `void fn
(int)'
x.cpp:5: error: after previous specification in `void fn(int)'
But Stroustrup in his book "The C++ Programming Language - Third
Edition(NOT the Special Third Edition)" has mentioned the following in
page 153 in section "7.5 Default Arguments":
A default argument can be repeated in a susequent declaration in the
same scope but not changed. Having this being stated, I do not
understand why the compiler is giving error. Have I misunderstood what
Sttroustrup has stated ? Kindly clarify.
Thanks
V.Subramanian