CompuServe Thread

#C++ Conversion Ops

2 messages in this thread
#7180From: Bob DelaneyJul 19, 1993 11:04 PM
Joe, The reason why I was getting a syntax error in trying to declare a conversion operator in the TCL class CDialogText was due to AppMaker's mapping of .cp extension files to the Think C compiler, not to Symantec C++. Thus CDialogText.cp was being compiled in Think C, and so gave a syntax error to operator long (); The main point of this reply is that, when one does compile the TCL with Symantec C++, conversion operators do work! I inserted into the public part of the class declaration of CDialogText (in the file CDialogText.h) the statement: operator long (); I put the actual procedure in CDialogText.cp as CDialogText :: operator long () { Str255 theString; long result; GetTextString( theString); // defined for the class CDialogText StringToNum( theString, &result); // standard toolbox call return result; } If inputString is an object of the class CDialogText containing a string suitable for conversion to a long, the statement long theNumber = inputString; works as expected. Bob
#7317From: Joe SewellJul 21, 1993 5:12 PM
Aha! I didn't think of that; when I initially built AppMaker's starter projects, I went ahead and changed the extension mapping immediately. (I was making some other starter projects customized for THINK C & C++, so I was in the habit of doing that already. 🙂 ) Joe