Declaring multiple object pointers on one line causes compiler error

后端 未结 5 1654
情话喂你
情话喂你 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:14

    In C++11 you have a nice little workaround, which might be better than shifting spaces back and forth:

    template using type=T;
    template using func=T*;
    
    // I don't like this style, but type i, j; works ok
    type i = new int{3},
               j = new int{4};
    
    // But this one, imho, is much more readable than int(*f)(int, int) = ...
    func f = [](int x, int y){return x + y;},
                        g = [](int x, int y){return x - y;};
    

提交回复
热议问题