零一参数构造函数

Zero-One argument Constructor

本文关键字:构造函数 参数      更新时间:2023-10-16
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] = '';
    this->m_name = nullptr;
    this->m_price = 0;
    this->m_Cquantity = 0;
    this->m_status = false;
    this->m_Nquantity = 0;
    this->m_type = '';
    this->m_unit[0] = '';
}

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

• 零一参数构造函数

此构造函数可以选择接收标识产品类型的字符。默认值为"N"。此函数

  • 将收到的字符存储在实例变量中

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

我构造了零参数构造

函数,但我不确定如何做零一参数构造函数。请帮帮我。

使用默认参数。

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