Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clion Unintialized record type: player

I have started learning C++ a few weeks ago. I am seeing now classes and all the stuff, and I was wondering about object instantiation. In this code:

class Player
{
    public:
        int x, y;
        int speed;
};

int main ()
{
    Player player {};

    return 0;
}

I get a warning from the IDE if I don't put braces in Player player {}. I use Clion 2017.2.3. The warning says: "Unintialized record type: player" and seems to come from Clang-Tidy, though I'm not sure what it really does.

So, is this important? Do I have to put braces in object instantiation or not?

Excuse me my mistakes, English is not my native language.

like image 580
vrodriguez Avatar asked Nov 02 '17 00:11

vrodriguez


1 Answers

If you don't provide an initialization list, the object is not initialized (since you have no default constructor), so the members have indeterminate values. Using the initialization list ensures that all the members are get a default initialization.

This warning alerts you to the fact that you may have uninitialized member variables.

See here for more details about this check that comes from clang-tidy.

like image 67
Barmar Avatar answered Sep 24 '22 02:09

Barmar