An error occurred while writing the program that redefined the default parameters, as shown in the following example:
#include <iostream> #include <stdlib.h>using namespace Std;class student{private:int Number;char name[10]; public:student (int n = 0, char *s = "No Name");}; student::student (int n = 0, char *s = "No Name") {number = n;strcpy_s (name, s);} int main () {Student S1;return 0;}
Ask others to find out why:
1: Default value of the parameter can only appear in function declarations , can not appear in the definition of a function , otherwise the parameter will appear To define default parameters repeatedly the error---->> grammar rules
1 definition and declaration separation: Default values can only appear in the declaration 2 definitions and declarations are not separated, default values can only appear in the definition
Exception : (vs2013 can present default values in the definition without appearing in the declaration)---->> don't take the standard seriouslyis as follows:
tested, under vc6.0 and Liunx platforms, when definitions and declarations are separated: default values can only appear in declarations
Programmers are recommended to do well by standard
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
[Debug] Redefine default parameters