如何在构造函数中初始化char数组样式字符串

Mat*_*ith 2 c++ arrays string

我有一个类,我正在序列化通过unix套接字发送它必须有一个字符串,我已存储为char数组.我可以在构造函数中初始化它与我在这里完成的方式不同吗?

typedef struct SerialFunctionStatus_t {
    SerialFunctionStatus_t() 
        : serial_rx_count(0), serial_tx_count(0), socket_rx_count(0), socket_tx_count(0) 
        { port[0] = '\0'; }
    uint32_t serial_rx_count;
    uint32_t serial_tx_count;
    uint32_t socket_rx_count;
    uint32_t socket_tx_count;
    char port[20];
} SerialFunctionStatus_t;
Run Code Online (Sandbox Code Playgroud)

fiz*_*zer 7

放入port()初始化列表.这会导致端口'值初始化'(12.6.2),对于内置数组,这意味着零初始化(8.5).