逗号左边的操作数没有效果? [英] left-hand operand of comma has no effect?

查看:901
本文介绍了逗号左边的操作数没有效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个警告消息中遇到了一些麻烦,它在一个模板容器类中实现

  int k = 0 ,l = 0; (k =(index + 1),l = 0; k  elements [k] = arryCpy [1] ; 
}
delete [] arryCpy;

这是我得到的警告

  cont.h:在成员函数`void Container< T> :: insert(T,int)'中:
cont.h:99:警告:逗号的左侧操作数没有任何作用
cont.h:在成员函数`void Container< T> :: insert(T,int)[with T = double]':
a5testing.cpp:21:从这里实例化
cont.h:99:warning:逗号左操作数没有效果
cont.h:在成员函数`void Container< T> :: insert(T,int)[with T = std :: string]':
a5testing.cpp:28:从这里实例化
cont.h:99:警告:逗号的左侧操作数不起作用
>退出代码:0


解决方案 逗号表达式 a, b,c,d,e 类似于

  {
a;
b;
c;
d;
return e;
}

因此, k 将只返回 l < (sizeC - index)

要合并条件,请使用&& ||

  k < sizeC&& l< (sizeC-index)//两者都必须满足
k< sizeC || l< (sizeC-index)//任何一个都可以。


I'm having some trouble with this warning message, it is implemented within a template container class

int k = 0, l = 0;
    for ( k =(index+1), l=0; k < sizeC, l < (sizeC-index); k++,l++){
        elements[k] = arryCpy[l];
    }
    delete[] arryCpy;

this is the warning i get

cont.h: In member function `void Container<T>::insert(T, int)':
cont.h:99: warning: left-hand operand of comma has no effect
cont.h: In member function `void Container<T>::insert(T, int) [with T = double]':
a5testing.cpp:21:   instantiated from here
cont.h:99: warning: left-hand operand of comma has no effect
cont.h: In member function `void Container<T>::insert(T, int) [with T = std::string]':
a5testing.cpp:28:   instantiated from here
cont.h:99: warning: left-hand operand of comma has no effect
>Exit code: 0

解决方案

The comma expression a,b,c,d,e is similar to

{
  a;
  b;
  c;
  d;
  return e;
}

therefore, k<sizeC, l<(sizeC - index) will only return l < (sizeC - index).

To combine conditionals, use && or ||.

k < sizeC && l < (sizeC-index)  // both must satisfy
k < sizeC || l < (sizeC-index)  // either one is fine.

这篇关于逗号左边的操作数没有效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆