Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c+中构造函数的初始化+;_C++ - Fatal编程技术网

C++ c+中构造函数的初始化+;

C++ c+中构造函数的初始化+;,c++,C++,我有一个关于构造函数的问题, 以下代码正常工作的原因: #include <iostream> using namespace std; class mycl { private: int a; //struct //{ char b,c; //} ms; public: mycl (int _a,char _b,char _c):a (_a), b (_b), c (_c){} }; int main() { /

我有一个关于构造函数的问题, 以下代码正常工作的原因:

#include <iostream>
using namespace std;
class mycl
{
private:
    int a;
    //struct
    //{
        char b,c;
    //} ms;

public:
    mycl (int _a,char _b,char _c):a (_a), b (_b), c (_c){}

};

int main() {
    // your code goes here
    mycl slc (15, 'a', 'f');
    return 0;
}
#包括
使用名称空间std;
mycl类
{
私人:
INTA;
//结构
//{
字符b,c;
//}ms;
公众:
mycl(int_a,char_b,char_c):a(_a),b(_b),c(_c){
};
int main(){
//你的密码在这里
mycl slc(15,'a','f');
返回0;
}

但这一次有一个编译错误

可以这样初始化复杂类型的成员吗

p、 美国。 谢谢你的翻译和回答。 抱歉,语言错误

您需要:

mycl(int _a, char _b, char _c) : a(_a), ms{_b, _c} {}
//                                      ^^^^^^^^^^

这是一个只有英语的网站。我投票将这个问题作为离题题题结束,因为这个问题不是英语的。也许你需要将此贴到:试试看你写什么?我看不懂。你是schreibst du吗?あなたは何を書いていますか?