备选1的C++矢量,重新使用的临时变量的优选方式矢量内存:填满结构
{
board.push_back(Sticker());
Sticker &sticker = board.back();
sticker.x = x + foreground.x;
sticker.y = foreground.y;
sticker.width = foreground.width;
sticker.height = foreground.height;
}
{
board.push_back(Sticker());
Sticker &sticker = board.back();
sticker.x = x + outline.x;
sticker.y = outline.y;
sticker.width = outline.width;
sticker.height = outline.height;
}
你更喜欢哪种方法?
编辑:为了讨论起见,假定任务必须由构造
我的建议为好,但我更喜欢'board.push_back(贴纸(轮廓,X)); board.push_back(贴纸(前景,x))'而不是逐一传递每个作品。 – 2010-03-28 15:35:06
Ya,在里面添加一个init列表,并且瞧' – Maciek 2010-03-28 15:43:59
你会怎样称呼你的构造函数参数,因为它们理想地应该和类成员具有相同的名字? – henle 2010-03-28 16:15:17