Stuck in function and booleans

后端 未结 2 1565
余生分开走
余生分开走 2021-01-29 14:02

I have function called firstRun(), inside of it I have two defined booleans filesDeleted and dirsDeleted.

Also inside in function

相关标签:
2条回答
  • 2021-01-29 14:13

    Change your

    bool filesDeleted;
    bool dirsDeleted;
    

    to

    bool filesDeleted = false;
    bool dirsDeleted = false;
    

    These are local variables and they must be assinged before use them.

    From 5.1.7 Local variables

    A local variable is not automatically initialized and thus has no default value. For the purpose of definite assignment checking, a local variable is considered initially unassigned.

    0 讨论(0)
  • 2021-01-29 14:19

    Unlike class member variables, local variables in methods do not have a default value, and must be definitely assigned before you try and read from them:

    so you need to use

    bool fileDeleted = false;
    bool dirsDeleted = false;
    

    instead of

    bool filesDeleted;
    bool dirsDeleted;
    
    0 讨论(0)
提交回复
热议问题