Struct Constructor in C++?

前端 未结 16 1815
轻奢々
轻奢々 2020-11-27 08:53

Can a struct have a constructor in C++?

I have been trying to solve this problem but I am not getting the syntax.

16条回答
  •  暖寄归人
    2020-11-27 09:35

    In C++ the only difference between a class and a struct is that members and base classes are private by default in classes, whereas they are public by default in structs.

    So structs can have constructors, and the syntax is the same as for classes.

提交回复
热议问题