home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!brunix!brunix!sdm
- From: sdm@cs.brown.edu (Scott Meyers)
- Subject: Overloading and Function Pointers
- Message-ID: <1992Jul23.210517.3915@cs.brown.edu>
- Sender: news@cs.brown.edu
- Organization: Brown University Department of Computer Science
- Date: Thu, 23 Jul 1992 21:05:17 GMT
- Lines: 41
-
- When you take the address of an overloaded function name, C++ is supposed
- to figure out which function to take the address of by looking at the type
- information. So consider this:
-
- class String {};
- String operator+(const String&, const String&);
-
- class Complex{};
- Complex operator+(const Complex&, const Complex&);
-
- template<class T> class Matrix {};
- template<class T> Matrix<T> operator+(const Matrix<T>&, const Matrix<T>&);
-
- typedef Matrix<int> (*PMIF)(const Matrix<int>&, const Matrix<int>&);
-
- void f()
- {
- String (*fp1)(const String&, const String&);
- fp1 = operator+; // must be op+ for Strings
-
- Complex (*fp2)(const Complex&, const Complex&) = operator+;
- // must be op+ for Complexes
-
- PMIF fp3 = operator+; // must be op+ for Matrix<int>s
- }
-
- cfront copes with fp1 and fp2 without any difficulty, but for fp3 it says:
-
- error: cannot deduce type for &overloaded operator +()
-
- Am I doing something wrong, or is this a compiler bug?
-
- Thanks,
-
- Scott
-
- PS - When I feed this to g++, it generates an internal error and then
- expires.
-
- -------------------------------------------------------------------------------
- What do you say to a convicted felon in Providence? "Hello, Mr. Mayor."
-