CompuServe Messages

#C++ Conversion Ops

    19-Jul-93 23:04:29
Sb: #C++ Conversion Ops
Fm: Bob Delaney 72255,1054
To: Joe Sewell 74136,360
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