听起来您想要一个“可选”返回参数。您似乎(并且正确地)不想使用 0.0 作为“无价值”结果,因为这意味着 0.0 不能用于实际值。
您有时会看到 2 个很好的解决方案是使用“结果代码”,或者使用指针作为返回结果。(指针更复杂)。我先从#1开始:
1.结果代码
// definitions for result codes
#define FAIL 0
#define OK 1
int GetNewValue(int feature, double *result) {
    switch( feature ) {
        case TYPE1:
            *result = 0.0 ;
            return FAIL ; // caller of the function should recognize
                          // the call "failed"
        case TYPE2:
            *result = 200.0 ;
            return OK ;
        default:
            *result = 47.0 ;
            return OK;
    }
}
// use:
double feature ;
int result = GetNewValue( 5, &feature ) ;
if( result == OK )
{
    // do something with "feature"
}
2. 使用指针
double* GetNewValue(int feature) {
    switch( feature ) {
        case TYPE1:
            return NULL ; // NO POINTER means FAIL
        case TYPE2:
            return new double(200) ;
        default:
            return new double( 47 ) ;
    }
}
// use:
double* result = GetNewValue( 5 ) ;
if( result != NULL )
{
    // result had a value, so you can use it
}
带指针的问题是你需要delete记住result
delete result ; // when done with pointer that was created
                // with `new`, you must `delete` it after
                // otherwise you'll get a memory leak