jeudi 4 janvier 2018

C++11 way to reset a struct to null?

I am learning a physics library and it involves creating info structs and then passing them to initialiser functions:

btRigidBodyConstructionInfo rbInfo = (/*values...*/);
btRigidBody* rigidBody = new btRigidBody(rbInfo);

Now I want to reset the struct (null it) to reuse it. I found another question on SO which is identical, and the answer was either to create a zero-initialised temporary and set it to it, or after C++11:

rbInfo = {};

When I tried this I got the message:

"No operator "=" matches these operands.

I was confused and but then found out that this syntax attempts to call the default constructor (at least in my compiler (Visual Studio 2017)), and rbInfo doesn't haven't any. I have a feeling that that syntax does the same as:

rbInfo = btRigidBodyConstructionInfo{};

In this case is there no way to reset the struct without setting the individual members? I thought about memsetting, but that's a bad idea generally because there might be things like vtable pointers and such, right?

Aucun commentaire:

Enregistrer un commentaire