Zero-One参数构造函数

时间:2018-04-10 02:32:09

标签: c++

const int max_sku_length = 7;
const int max_unit_length = 10;
const int max_name_length = 75;
const double TRate = 0.13;
char m_type;
char m_sku[max_sku_length +1];
char m_unit[max_unit_length + 1];
char* m_name;
int m_Cquantity;
int m_Nquantity;
double m_price;
bool m_status;

Product()
{
    this->m_sku[0] = '\0';
    this->m_name = nullptr;
    this->m_price = 0;
    this->m_Cquantity = 0;
    this->m_status = false;
    this->m_Nquantity = 0;
    this->m_type = '\0';
    this->m_unit[0] = '\0';
}

我是C ++的新手。我需要创建一个

•Zero-One参数构造函数

此构造函数可选地接收标识产品类型的字符。默认值为“N”。这个功能

  • 将字符接收存储在实例变量

  • 将当前对象设置为安全可识别的空状态。

我构造了零参数构造函数,但我不确定如何做Zero-one参数构造函数。请帮帮我。

1 个答案:

答案 0 :(得分:1)

使用默认参数。

Product::Product (char productType = 'N') {
    // your stuff
}