On Sat, 2007-06-16 at 09:47 +0530, anitha boyapati wrote: > Hi John, > > > > using namespace std; > > > class test { > > > public : > > > test() { }; > > > > I was surprised that g++ compiled your code (after removing the first > > function and leaving the overloaded one) although you have a semicolon > > after the function test(), which is something I've never seen before and > > thought was invalid !!! > > Its a pretty much common pratice in the enviroment I work - although > an inelegant one. > But why should it not work ?
Simply because it doesn't confirm with the C++ standard, as far as I know. > I didnot think about static_cast<bool> or casting either for that matter. I'm sorry about the above statement, it was a kind of misleading. Usually, conversions that can be done using explicit casting and not implicitly don't govern the compiler decisions of which function to call. The problem here is that the conversion can be done implictly without an explicit casting. According to Stroustrup's C++ book, "A pointer can be implicitly converted to a bool (§C.6.2.5). A nonzero pointer converts to true and a zero valued pointers converts to false." Which is also why the program will compile if you removed the overloaded version of the function. Note: The above statement about pointers hold true for integer types. A nonzero integer value can be assigned to a boolean variable as a true and a zero variable becomes false. This behavior is very important so that old C code (i.e. using a pointer in the if conditional statement) can be compiled successfully under the C++ compilers despite its strict type checking. -- John V. Shahid <[EMAIL PROTECTED]> _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus