Created
December 2, 2014 15:40
-
-
Save somma/52f6297e7d81c3859c7d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @brief 포인터 타입에 상관없이 free() and Nil 을 수행하는 템플릿 함수 | |
void my_free(void*& ptr) | |
{ | |
... | |
} | |
char* char_ptr; | |
void* void_ptr; | |
... | |
my_free(char_ptr); // error C2664: 'my_free' : cannot convert parameter 1 from 'char *' to 'void *&' | |
my_free(void_ptr); // error C2664: 'my_free' : cannot convert parameter 1 from 'char *' to 'void *&' | |
**/ | |
template <typename T> inline void my_free(T& ptr) | |
{ | |
if (NULL != ptr) | |
{ | |
free(ptr); | |
ptr = NULL; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment