#include <iostream>
#include <vector>
using namespace std;
//
// Below is what I want but not legal in current C++!
//
vector<int> operator ...(int first, int last)
{
vector<int> coll;
for (int i = first; i <= last; ++i)
{
coll.push_back(i);
}
return coll;
}
int main()
{
for (auto i : 1...4)
{
cout << i << endl;
}
}
我想通过使用语法1...100
,7...13
,2...200
等来生成整数序列。是否有可能在C++中重载运算符“...”?
我想在C++中重载...
。
可能吗?
你想让你的代码尽可能不可读吗? –
'......'根本不是运营商。检查[这里](http://stackoverflow.com/questions/4421706/operator-overloading)有什么可用。 –
那么..你不能_overload_不存在的操作符.. –