我在使用此警告消息时遇到了一些麻烦,它是在模板容器类中实现的
int k = 0, l = 0;
for ( k =(index+1), l=0; k < sizeC, l < (sizeC-index); k++,l++){
elements[k] = arryCpy[l];
}
delete[] arryCpy;
这是我得到的警告
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
最佳答案
逗号表达式a,b,c,d,e
与
{
a;
b;
c;
d;
return e;
}
因此,
k<sizeC, l<(sizeC - index)
将仅返回l < (sizeC - index)
。要组合条件,请使用
&&
或||
。k < sizeC && l < (sizeC-index) // both must satisfy
k < sizeC || l < (sizeC-index) // either one is fine.
关于c++ - 左手逗号操作数有没有效果?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2839597/