将对象添加到矢量的正确方法是什么?看来,一个向量拍摄对象的副本,而不是实际的对象...创建对象并将其推入矢量的正确方法是什么?
例如:
class MyClass{
private:
std::vector<Texture>_textures;
public:
void addATexture(int textureWidth,int textureHeight){
Texture tex(textureWidth,textureHeight);
_textures.push_back(tex);//A copy of tex is pushed into in..
} // ---> At this point, tex is destroyed...
}
什么是摆在矢量对象的正确方法,没有副本?
如果副本有副作用,则不会被消除 – Danh