Mic*_*ock 4 c++ stdvector c++11
考虑std::vector<T>某种类型T.我收到一个指向这种类型的指针到函数中,也是一个实例T; t说.
我的功能看起来像这样:
void bar(std::vector<T>* foo, const T& t)
{
foo->clear();
foo->push_back(t);
}
Run Code Online (Sandbox Code Playgroud)
有没有办法在一个语句中编写函数体?*foo = t;由于不存在适当的赋值运算符而无法工作.我也在考虑使用
foo->assign(&t, &t + 1);
Run Code Online (Sandbox Code Playgroud)
但那似乎很顽皮.
我正在使用C++ 11.
| 归档时间: |
|
| 查看次数: |
168 次 |
| 最近记录: |