I understand another's code and came across the following:

CClientHandler* handler = new CClientHandler(sock, b); (void)handler; 

What does (void) before the handler pointer?

    2 answers 2

    View strings

     (void)handler; 

    or

     handler; 

    commonly used to get rid of the "Variable ... not used" compiler warnings. If further on the code the pointer is used, then this line can be deleted.

    https://stackoverflow.com/questions/21045615/what-does-voidvar-actually-do

    • 2
      Just mentioning a variable (without casting) will result in another warning: expression result unused . - αλεχολυτ

    The easiest way to find out is to comment out the given line and compile it. If further in the text of the function there is no mention of handler , then the exception of the string (void)handler; would result in a warning about an unused variable (at the appropriate compiler alert level) (which is already mentioned in the @goldstar_labs answer).

    However, in the situation mentioned, one could simply reduce the code to the following form:

     new CClientHandler(sock, b); 
    • In fact, something suggests a possible memory leak ... - Harry
    • @Harry suggests. But exactly the same sin and the source code. We assume that inside this constructor, this somehow saved for later deletion. - αλεχολυτ
    • And I'm talking about him :) - Harry