home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13334 < prev    next >
Encoding:
Text File  |  1992-09-07  |  1.1 KB  |  36 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: pointer to member function.
  5. Message-ID: <1992Sep5.164303.19876@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <1992Sep5.015422.2429@unixland.natick.ma.us>
  8. Date: Sat, 5 Sep 1992 16:43:03 GMT
  9. Lines: 25
  10.  
  11. dlb@unixland.natick.ma.us (David L. Briggs) writes:
  12.  
  13. >    A simple question.  If you have a class that has several functions
  14. >with the same name that are overloaded, how can you take the address of one
  15. >of these function?
  16.  
  17. You have to take the address in a context where the desired function
  18. type is specified.  You normally take the address so as to assign it
  19. to a pointer-to-member-function, or to pass to a function parameter of
  20. that type.  Type matching resolves the ambiguity if possible.
  21.  
  22. class X {
  23. public:
  24.     int foo(int);
  25.     int foo(double);
  26.     int foo(int, int);
  27. };
  28.  
  29. int (X::*p1)(int)    = &X::foo; // foo(int)
  30. int (X::*p2)(double)    = &X::foo; // foo(double)
  31. int (X::*p3)(int,int)    = &X::foo; // foo(int, int)
  32. -- 
  33.  
  34. Steve Clamage, TauMetric Corp, steve@taumet.com
  35. Vice Chair, ANSI C++ Committee, X3J16
  36.