home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11436 < prev    next >
Encoding:
Text File  |  1992-07-23  |  1.6 KB  |  52 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!brunix!brunix!sdm
  3. From: sdm@cs.brown.edu (Scott Meyers)
  4. Subject: Overloading and Function Pointers
  5. Message-ID: <1992Jul23.210517.3915@cs.brown.edu>
  6. Sender: news@cs.brown.edu
  7. Organization: Brown University Department of Computer Science
  8. Date: Thu, 23 Jul 1992 21:05:17 GMT
  9. Lines: 41
  10.  
  11. When you take the address of an overloaded function name, C++ is supposed
  12. to figure out which function to take the address of by looking at the type
  13. information.  So consider this:
  14.  
  15.   class String {};
  16.   String operator+(const String&, const String&);
  17.  
  18.   class Complex{};
  19.   Complex operator+(const Complex&, const Complex&);
  20.  
  21.   template<class T> class Matrix {};
  22.   template<class T> Matrix<T> operator+(const Matrix<T>&, const Matrix<T>&);
  23.  
  24.   typedef Matrix<int> (*PMIF)(const Matrix<int>&, const Matrix<int>&);
  25.  
  26.   void f()
  27.   {
  28.     String (*fp1)(const String&, const String&);
  29.     fp1 = operator+;                          // must be op+ for Strings
  30.  
  31.     Complex (*fp2)(const Complex&, const Complex&) = operator+;
  32.                                               // must be op+ for Complexes
  33.  
  34.     PMIF fp3 = operator+;                     // must be op+ for Matrix<int>s
  35.   }
  36.  
  37. cfront copes with fp1 and fp2 without any difficulty, but for fp3 it says:
  38.  
  39.   error: cannot deduce type for &overloaded operator +()
  40.  
  41. Am I doing something wrong, or is this a compiler bug?
  42.  
  43. Thanks,
  44.  
  45. Scott
  46.  
  47. PS - When I feed this to g++, it generates an internal error and then
  48.      expires.
  49.  
  50. -------------------------------------------------------------------------------
  51. What do you say to a convicted felon in Providence?  "Hello, Mr. Mayor."
  52.