gpt4 book ai didi

c++ - 在 C++ 中,是否有更有效的方法来编写多个声明

转载 作者:行者123 更新时间:2023-11-28 00:54:37 25 4
gpt4 key购买 nike

在C++中,有没有更高效的写法:

ImageButton* imageButton;
ImageButton* imageButton1;
ImageButton* imageButton2;
ImageButton* imageButton3;

等而不写出所有行?我有超过 1000 个按钮。我希望有更好的写这个的方法。

谢谢

最佳答案

如果您坚持使用多个变量,请在一行中这样做。

ImageButton *imageButton, *imageButton1, *imageButton2 ;

你也可以通过一种方法消除星星,但这种方法与你的方法几乎一样差或好。如果使用对象数组,IT 会更好。

ImageButton [] ;

或者动态的,如果你想在之后发展的话。

ImageButton * imagebutton = new ImageButton [size] ;

关于c++ - 在 C++ 中,是否有更有效的方法来编写多个声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12184649/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com