双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

vector += 1, 2, 4, 5;

cxjddd cxjddd 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
听说 boost 库现在可以这样了:
vector<int> v;
v += 1, 2, 4, 5;
所以想自己实现一下:

#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

template <typename T>
vector<T> &operator += (vector<T> &v, T t)
{
v.push_back (t);
return v;
}

template <typename T>
vector<T> &operator , (vector<T> &v, T t)
{
v.push_back (t);
return v;
}

int main()
{
vector<int> v;
v += 1, 2, 3, 4;
for (vector<int>::iterator i = v.begin(); i != v.end(); ++i)
cout << *i << endl;

system ("pause");
return 0;
}
...全文

相关推荐

评论 16
收藏 已收藏
分享
返回顶部
cxjddd
其它技术问题 3,881 成员 9,044 内容