Declaring multiple object pointers on one line causes compiler error

后端 未结 5 1663
情话喂你
情话喂你 2020-11-27 21:49

when I do this (in my class)

public:
    Entity()
    {
        re_sprite_eyes = new sf::Sprite();
        re_sprite_hair = new sf::Sprite();
        re_spri         


        
5条回答
  •  情话喂你
    2020-11-27 22:12

    The asterisk binds to the pointer-variable name. The way to remember this is to notice that in C/C++, declarations mimic usage.

    The pointers might be used like this:

    sf::Sprite *re_sprite_body;
    // ...
    sf::Sprite sprite_bod = *re_sprite_body;
    

    Similarly,

    char *foo[3];
    // ...
    char fooch = *foo[1];
    

    In both cases, there is an underlying type-specifier, and the operator or operators required to "get to" an object of that type in an expression.

提交回复
热议问题