这些是否有效地做同样的事情?
vector<MyType> stuff;
MyClass(MyType *things, int numThings){
for (int i = 0; i < numThings; ++i){
//stuff[i] = things[i]; //original version of question, fixed
stuff.push_back(things[i]);
}
}
对比
vector<MyType> stuff;
MyClass(MyType *things, int numThings) : stuff(things, things+numThings) {}//fixed
如果是的话,使用这两种方法的开销有多大?(方法一中的额外打字除外)