Cyberdrek, couldn''t you use templates to solve that though?
"You don''''t get wise with the sleep still in your eyes." - Neil Peart
#define vs const
Yes, that's one of the things templates do best!
![](smile.gif)
template
inline const T& min(const T& a, const T& b) { return (a < b) ? a : b; }
template
inline const T& max(const T& a, const T& b) { return (a > b) ? a : b; }
These functions are part of the C++ standard library algorithms - why bother defining them yourself?
Edited by - null_pointer on March 24, 2001 7:37:34 AM
I''ll believe that inline functions are better when somebody can give me the inlined equivalent of this simple macro, which I use in every single project I work on:
C''mon, just gimme that inline function, then I''ll believe you guys. Honest.
-----------------
The Goblin (madgob@aol.com)
-----------------
"Before critisizing somebody, walk a mile in their shoes. That way, when you do critisize them, not only will you be a mile away, but you''ll also have their shoes!"
#define SafeRelease(p) { if ( (p) ) { (p)->Release(); (p) = 0; } }
C''mon, just gimme that inline function, then I''ll believe you guys. Honest.
-----------------
The Goblin (madgob@aol.com)
-----------------
"Before critisizing somebody, walk a mile in their shoes. That way, when you do critisize them, not only will you be a mile away, but you''ll also have their shoes!"
- The Goblin (madgob@aol.com)
|
I think that should work. I''m not saying that templates or inlines are better, but they do have their own applications.
"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
![Resist Windows XP''s Invasive Production Activation Technology!](http://www.crosswinds.net/~druidgames/resist.jpg)
http://www.gdarchive.net/druidgames/
You asked for it.
template <typename T>
inline void safe_release(T*& p)
{ if( p ) { p->Release(); p = 0; } }
Now remember your part of the bargain.
![](smile.gif)
Null and Void: That won't work, you're setting a temporary copy of the pointer to 0, not the real pointer. Also, the parentheses aren't necessary because you are dealing with a real variable in a real function.
Edited by - null_pointer on March 25, 2001 8:28:55 AM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement