Path: utzoo!attcan!uunet!clyde.concordia.ca!mcgill-vision!bloom-beacon!eru!luth!sunic!mcsun!ukc!acorn!abccam!pete From: pete@abccam.abcl.co.uk (Peter Cockerell) Newsgroups: comp.lang.c++ Subject: Zortech C++ 2.06 bug Keywords: zortech bug c++ Message-ID: <20@pete.abccam.abcl.co.uk> Date: 12 Feb 90 15:28:26 GMT Organization: Active Book Company Limited, Cambridge, UK Lines: 46 Has anyone come across this bug in Zortech C++ 2.06, and is there a fixed version? class String { char *str; ... public: //Various constructors String(char*); String(S&); String(int); //Various type convs. operator char*() { return str; } operator int() { return *str != '\0'; }//ie return *this is non-null String& operator=(String&); ... }; ... main() { String c1="Y", c2="N"; String res; res = 1 ? c1 : c2; printf((char*)res); } This prints 1. The reason is not that the 1 from the conditional expression is being converted to a String, as you might at first guess, but because the second expression, c1, is for some reason automatically being cast to an int (using the operator int()) yielding 1, which is then being cast to a String for the assignment. (That's what it looks like from the code generation anyway.) If you say instead if (1) res=c1; else res=c2; you get Y printed, as you might expect. Any comments?