c++ - why does fclose not set file pointer to NULL? -


I was writing an RAI wrapper for FILE *. I have seen that when the file is destroyed after being deleted * it leads to undefined behavior (sig mistake or errors somewhere else). I think the fclose file will be set * null *, which did not do it. smartFP {smartFP (const std :: string and name): fp (fopen (name.c_str), "r") {} ~ smartFP () {if (fp) {Fclose (Fp); // delete (fp); & Lt; - The cause of the accident is fp = null; & Lt; - Is this OK?}} Private: FILE * fp;};

  • Why does fclose FILE * not set to taps?
  • The second question allocates the FP to the FP in the heap or the heap? I thought it was on the heap and so remove it after Fclose, so that the 4 or 8 bytes can be de-olotted on the heap for the FP. But it seems that it is not needed.

    Of course delete fp is causing an accident. It was not allocated with new . Call only Delete with something you've got a new or you have been asked to use it with some other documents. The document for fopen will never allow you to delete all the cleaning fclose ; You do not need to do anything after releasing file-related resources.

    Setting fp = NULL OK This is probably desirable so that the future consumer "Smart File Notifier" can check whether the indicator is still valid or not. (This is more useful than the method from a reset to the destroyer, though; after the execution of the pest, the indicator class can not have any future users because the objects are no longer present.) But < Code> fclose can not do this because because fclose does not get its parameters based on context, and even if it does, then it everyone Will not be able to cancel the possibility of file indicator Remember Ian that free and Delete are set to NULL to their argument,

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -