为什么将默认参数构造函数称为默认构造函数 [英] Why default argument constructor is called as default constructor

查看:100
本文介绍了为什么将默认参数构造函数称为默认构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Class A {
public:
       A(int i = 0, int k = 0) {} // default constructor WHY ??
       ~A() {}
};
int main()
{
  A a; // This creates object using defined default 
       // constructor but the constructor still has two arguments
  A b(1,2); // Called as parametrized one
}

为什么此默认参数构造函数是默认构造函数。为什么不将其称为参数化构造函数或默认参数化构造函数,因为即使不使用任何参数调用该构造函数,它也确实包含两个参数?

Why this default argument constructor is default constructor. Why it is not called Parametrized constructor or default parametrized constructor because even if this constructor is called with no arguments it does contain two arguments ?? Is there any specific reason or its just because the standard says so.

推荐答案


C ++ 11 §12.1构造函数


类X的默认构造函数是类X的构造函数,无需参数即可调用。

C++11 §12.1 Constructors

A default constructor for a class X is a constructor of class X that can be called without an argument.

这是默认构造函数的定义。可以为所有参数提供默认参数的构造函数 不带参数地调用,因此符合定义。

This is the definition of default constructor. A constructor that supplies default arguments for all its parameters can be called without argument, thus fits the definition.

这篇关于为什么将默认参数构造函数称为默认构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆