Checking if a variable is initialized

前端 未结 13 1466
后悔当初
后悔当初 2020-12-28 11:59

Seems like this would be a duplicate, but maybe it is just so obvious it hasn\'t been asked...

Is this the proper way of checking if a variable (not pointer) is init

13条回答
  •  太阳男子
    2020-12-28 12:20

    If for instance you use strings instead of chars, you might be able do something like this:

        //a is a string of length 1
        string a;
        //b is the char in which we'll put the char stored in a
        char b;
        bool isInitialized(){
          if(a.length() != NULL){
            b = a[0];
            return true;
          }else return false;
        }
    

提交回复
热议问题