标签:重定义默认参数
编写程序过程中遇到重定义默认参数的错误,如下例所示:
#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;
}
请教他人发现了原因所在:
1:参数的默认值只可以出现在函数声明中,不可以出现在函数的定义中,否则会出现参数重复定义默认参数的错误---->>语法规定
建议编程者还是按标准做得好
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:重定义默认参数
原文地址:http://blog.csdn.net/zongyinhu/article/details/46941583