Errore del compilatore C3487
'return type': tutte le espressioni restituite devono essere dedotte dallo stesso tipo. In precedenza era 'return type'
Un'espressione lambda deve specificare il tipo restituito a meno che non contenga una singola istruzione return. Se un'espressione lambda contiene più istruzioni return, devono avere tutte lo stesso tipo.
Per correggere l'errore
- Specificare un tipo restituito finale per l'espressione lambda. Verificare che tutti i valori restituiti dall'espressione lambda siano dello stesso tipo o possano essere convertiti in modo implicito nel tipo restituito.
Esempio
L'esempio seguente genera l'errore C3487 perché i tipi restituiti dell'espressione lambda non corrispondono:
// C3487.cpp
// Compile by using: cl /c /W4 C3487.cpp
int* test(int* pi) {
// To fix the error, uncomment the trailing return type below
auto odd_pointer = [=]() /* -> int* */ {
if (*pi % 2)
return pi;
return nullptr; // C3487 - nullptr is not an int* type
};
return odd_pointer();
}