我正在协助用c++为Nintendo DS编写游戏(它有约3MB的RAM)。在界面中的所有菜单上,通过调用void函数创建了一个“按钮”,该函数将背景瓷砖设置为按钮。界面中至少有30个按钮。现在,我创建了一个按钮类,存储其位置、标签等其他数据值。
当程序离开对象的作用域后,所有这些新按钮对象会影响RAM使用情况(或其他性能方面)吗?
还是说只要程序离开创建它的函数,对象就会被自动丢弃?
以下是一些代码:
#include "Button.h"
void titlescreen() //Called to create main menu
{
Button singlePlayer = Button(4, 5, "Single Player");
//Creates button at coord (4,5)
Button multiPlayer = Button(4, 8, "Multi Player");
bool chosen = false; //Whether an option has been clicked
while(!chosen)
{
//Menu stuff here
}
}
Button.h:
#include <stdio.h>
#ifndef BUTTON_H
#define BUTTON_H
class Button
{
public:
int length;
int x, y;
bool isColored;
void setColored(bool);
void setDefault();
button(int, int, const char * const); //Constructor
button(int, int, const char * const, int); //Constructor
};
#endif /* BUTTON_H */
class Button
(B 大写)吗? - dlf