[Debug] Redefine default parameters

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.