home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18817 < prev    next >
Encoding:
Text File  |  1993-01-07  |  2.0 KB  |  63 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!munnari.oz.au!titan!cetra!lightw
  3. From: lightw@cetra.trl.OZ.AU (Liron Lightwood)
  4. Subject: Help. Is this a templates bug?
  5. Message-ID: <1993Jan8.003633.17575@trl.oz.au>
  6. Sender: root@trl.oz.au (System PRIVILEGED Account)
  7. Organization: Telecom Research Labs, Melbourne, Australia
  8. Date: Fri, 8 Jan 1993 00:36:33 GMT
  9. Lines: 52
  10.  
  11. I was experimenting with templates for use in our project, when I managed to
  12. obtain a compiler error message which effectively said that there was an
  13. error with the argument given to the constructor, even though what it got
  14. was identical to what it expected.
  15.  
  16. Is this a bug with templates, or the compiler I am using?
  17. How can I overcome it?
  18.  
  19. I am using an AT&T C++ 3.01 compiler on a SUN SPARCstation running under
  20. SUNOS 4.1.1.
  21.  
  22. Here is the code, followed by the error message.
  23.  
  24. -------------------------------------------------------------------
  25. class x
  26. {
  27.     public:
  28.     int x_int() { return 21; }
  29.          // x_int is a member function of class x which returns an
  30.          // integer
  31. };
  32.  
  33. template <class A,class B> class GetFunc {
  34. public:
  35.    B (A::*a_b_func)();  
  36.         // func contains address of a member function of class A 
  37.         // (e.g. class x) which returns an B (e.g. an int) 
  38.  
  39.    GetFunc(B (A::*f)()) : a_b_func(f) {}  // constructor
  40. };
  41.  
  42. main()
  43. {
  44.     GetFunc<x,int> getfunc_x_int ( &(x::x_int) );
  45. }
  46.  
  47.  
  48. --------------------------------------------------------------------
  49.  
  50. Here is the compiler error message:
  51.  
  52. /usr/local/bin/CC a.c
  53. CC  a.c:
  54. "a.c", line 20: error: bad argument  1 type for  GetFunc <x, int >::GetFunc__pt__4_1xi(): int (x::*)() ( int (x::*)() expected)
  55.  
  56. ------------------------------------------------------------------------
  57.  
  58.  
  59. Liron Lightwood                     Internet : r.lightwood@trl.oz.au
  60. Telecom Research Laboratories       Phone : +61 3 253 6535
  61. 770 Blackburn Road                  Snail : P.O. Box 249 Clayton 3168 Australia
  62. Clayton  Vic. 3168 Australia        Disclaimer : My views are not my company's
  63.