Re: (off-topic) RE: [Doxygen-users] Documenting IDL
Brought to you by:
dimitri
From: Hendrik S. <Do...@HS...> - 2001-06-10 21:29:21
|
"Stephen Goudge" <ste...@pi...> wrote: > [...] > I did originally have an operator int() that could be used in if-statements, > which worked fine using VC++2 through to VC++4; then a client bought VC++5 and > it became ambiguous (I forget the precise reason why), so everything switched to > IsValid() from then on. 'int' seems like one of the most troublesome ideas. (What's 'spa+spb' to become then?) > [...] > Even with a decent compiler, there is the vexed question of what the cast > operator should be casting _to_ - you don't really want to return another > pointer type, as that looks too much like you're providing a backdoor. These > days, 'bool' would be a reasonable choice (now that the compilers actually > support 'bool'). The best choice would be the mythical 'logical' type that 'if', > 'while' etc use, but that isn't available :-( Oh, but that's available: It's named 'bool'. But 'bool' isn't all that good either, because it's an arithmetic type. (Or was it convertible into one?) You could thus write 'sp+5' and get funny results. In his book "Modern C++ Design" Andrei Alexandrescu discusses this issue. His idea (typing from memory): template<class T> class SmartPtr { private: class Tester { void operator delete(void*); }; public: operator Tester*() const { if( !IsValid() ) return NULL; static Tester tester; return tester; } // ... }; (The private 'operator delete()' is there to prevent users from trying to delete the result of calling the convertion operator.) I have not used this yet, so I don't know whether it's really as great an idea as it seemed to me. > Stephen Goudge Schobi |