2010-05-15 18 views
7

Sto avendo qualche problema con questo messaggio di avviso, è implementato all'interno di una classe template containerL'operando a sinistra della virgola non ha alcun effetto?

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

questo è il monito ottengo

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 

risposta

16

L'espressione virgola a,b,c,d,e è simile a

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

pertanto, k<sizeC, l<(sizeC - index) torneranno solo l < (sizeC - index).

Per combinare condizionali, utilizzare && o ||.

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

Passa a:

for (k =(index+1), l=0; k < sizeC && l < (sizeC-index); k++,l++){ 

Quando si valuta un'espressione virgola, viene restituito l'argomento più a destra in modo che:

k < sizeC, l < (sizeC-index) 

espressione restituisce:

l < (sizeC-index) 

e non trova quindi

k < sizeC 

usa la && combinare le condizioni invece.

4

L'espressione k < sizeC, l < (sizeC-index) restituisce solo il risultato del test di destra. Utilizzare && combinare prove:

k < sizeC && l < (sizeC-index) 
Problemi correlati