Is this C++ structure initialization trick safe?

前端 未结 16 1181
有刺的猬
有刺的猬 2020-12-23 17:56

Instead of having to remember to initialize a simple \'C\' structure, I might derive from it and zero it in the constructor like this:

struct MY_STRUCT
{
            


        
16条回答
  •  青春惊慌失措
    2020-12-23 18:28

    If you already have a constructor, why not just initialize it there with n1=0; n2=0; -- that's certainly the more normal way.

    Edit: Actually, as paercebal has shown, ctor initialization is even better.

提交回复
热议问题