home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 2147 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  62 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: news2.interlog.com!rose!awhite
  3. From: awhite@user.rose.com (A White)
  4. Subject: overloading operator()
  5. Sender: news@rose.com (news)
  6. Organization: Rose Media Incorpoarted, Ontario, Canada
  7. Message-ID: <DLusrq.JzL@rose.com>
  8. Date: Sat, 27 Jan 1996 18:59:49 GMT
  9.  
  10. I've been typing in a String class example from a C++ textbook
  11. (Obj-Orient Pgming in C++, Barkakati) and one portion does not work.
  12.  
  13. It involves overloading operator()
  14.  
  15. A stripped down version follows, with constructors/destructors and 
  16. unnecessary variables and functions removed.  The error given by
  17. SAS/C v6.50 is shown below the offending line...
  18.  
  19. Thanks in advanc...
  20.    Allen White
  21.  
  22. // STRING.HXX
  23. class String {
  24.    protected:
  25.       char   *_string;
  26.       size_t  _length;
  27.    
  28.    public:
  29.       // function call operator
  30.       SubString operator()( size_t position, size_t length );
  31. };
  32.  
  33. ====================
  34.       SubString operator()( size_t position, size_t length );
  35.                        ^
  36. String.hxx  Error 1200: Syntax error in member list:
  37.                Expected member declaration; found 'operator'.
  38.  
  39. class SubString: public String
  40. {
  41.    public:
  42.       // gives the String class access to SubString
  43.       friend String;
  44.       
  45.       // Constructors
  46.       SubString( const SubString& string ):
  47.          String( string ), _original( string._original ), 
  48.          _position( string._position ) {}
  49. }
  50.  
  51. // STRING.CXX
  52. #include "String.hxx"
  53.  
  54. SubString String::operator()( size_t position, size_t length )
  55. {
  56.    return SubString( *this, &( _string[ position ] ), position, length );
  57. }
  58. ====================
  59. String.cxx Error 1374: No such member 
  60.    ' SubString String::operator ()(unsigned int , unsigned int )'.
  61.  
  62.