Struct Constructor in C++?

前端 未结 16 1786
轻奢々
轻奢々 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:30

    struct HaveSome
    {
       int fun;
       HaveSome()
       {
          fun = 69;
       }
    };
    

    I'd rather initialize inside the constructor so I don't need to keep the order.

提交回复
热议问题