对的矢量-逗号操作数的左手边没有影响
Vector of pairs - left hand side of operand of comma has no effect
我声明了一个向量a与配对
vector <pair <int, int> > args;
然后我想把一对像这样推到向量中:
args.push_back((1,-1));
它告诉我逗号的左边操作数没有效果。我哪里错了?
说出args.push_back(std::make_pair(1,-1));
。或者任何数量的替代品:
// #1
args.push_back(std::pair<int, int>(1,-1));
// #2
typedef std::vector< std::pair<int, int> > pvector;
pvector args;
args.push_back(pvector::value_type(1,-1));
// #3
typedef std::pair<int, int> intpair;
std::vector<intpair> args;
args.push_back(intpair(1,-1));
// #4
args.emplace_back(1, -1); // sexy
//...
(1,-1(是一种语法,意思是"计算1,计算-1,然后使用-1作为值"。这与制作这对情侣的实例无关。你必须使用std::make_pair(1,-1)
来制作你推的那对。
相关文章:
- 为什么返回类型的'const'限定符对标有 __forceinline/内联的函数没有影响?
- 是否有任何区域设置会影响宽字符编码?
- 使用 std::move 将参数传递给函数,如果该参数声明为按值传递或使用移动操作数 &&,是否有区别?
- 此分配对速度有影响吗?
- "virtual"对C++析构函数有何影响?
- 如果我对"while"块发表评论,为什么程序会死机?其中的"yield"线有何影响?
- 当在循环中使用时,std::shared_ptr 对该循环的矢量化有任何影响吗?
- 明确定义'static const variable in a struct'对C++ 11 及以上有什么影响吗?
- 每个帧的参考中都有多少性能影响
- 与任何算术操作员都会影响优化的恒定操作数顺序
- 有没有办法修复此错误:与'operator[]'不匹配(操作数类型为 'empl' 和"int")
- 有多少操作数可以超载函数呼叫操作员采用
- 等号在大括号初始化中是否有影响?例如。 'T a = {}'与'T a{}'
- 点运算符可以有右操作数的表达式吗?为什么
- 完成的线程是否对 winapi 中的主程序有影响
- 在 c++ 中使用 "this" 关键字对性能有影响吗?
- 额外的继承对对象结构或实例化有影响吗?
- 当do额外的括号有影响时,除了运算符优先级
- Array2的变化对Array(表)有影响
- try-catch对char**返回值有影响