Correct way of initializing a struct in a class constructor

前端 未结 5 600
灰色年华
灰色年华 2020-12-08 02:44

So I want to add a struct from a c header file as a class member to a c++ class. But I get a compiler error for the cpp file: bar was not declared inn thi

5条回答
  •  一生所求
    2020-12-08 03:21

    Initialization should be done this way (C++11):

    myClass::myClass(  )
    : bar{1, 0, "someString", 0x4}
    {
    
    }
    

    Also, do not forget to declare your constructor in your class definition.

提交回复
热议问题