home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16424 < prev    next >
Encoding:
Internet Message Format  |  1992-11-17  |  1.7 KB

  1. Xref: sparky comp.lang.c++:16424 gnu.g++.help:1445
  2. Newsgroups: comp.lang.c++,gnu.g++.help
  3. Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!sgiblab!munnari.oz.au!cs.mu.OZ.AU!lenard
  4. From: lenard@mullian.ee.mu.OZ.AU (rohan james lenard)
  5. Subject: Template question with g++/gcc
  6. Message-ID: <lenard.722005741@munagin>
  7. Summary: Need advise on a template question with g++/gcc
  8. Sender: news@cs.mu.OZ.AU
  9. Organization: Computer Science, University of Melbourne, Australia
  10. Date: Tue, 17 Nov 1992 13:09:01 GMT
  11. Lines: 50
  12.  
  13. I have a question regarding template and g++/gcc.
  14. According to the ARM something like this should be valid -
  15.  
  16. >    template<class T,char *V> class foo
  17. >    {
  18. >        foo(char *filename = V) {} ;
  19. >    }
  20. ...
  21. >    foo<int,"Hello">    a;
  22.  
  23. However g++/gcc (2.2.2) complains pretty mightily about it.
  24. I have tried something like this -
  25.  
  26. >    class A
  27. >    {
  28. >        const char *str = "Hello";
  29. >        operator char * () const { return str; }
  30. >    }
  31. >    template<class T,class V> class foo
  32. >    {
  33. >        foo(char *filename = (char *)V) {} ;
  34. >    }
  35. >
  36. >    foo<int,A>        a;
  37.  
  38. and it can be made to work, but it is not as elegant.
  39.  
  40. Does anyone have a work around so that I can use something like the first
  41. example ? (NOTE: I may not have my code syntactically correct, as I am trying
  42. to remember it from a few days ago at a friends work, but I assume you get the
  43. idea)
  44.  
  45. Any help would be appreciated.
  46.  
  47. As an aside (sp?), the examples in the ARM for this sort of template class
  48. both work - did GNU only use these or what :-) ?
  49.  
  50.  
  51. Thanks in advance,
  52. Regards,
  53.     Rohan
  54. --------------------------------------------------------------------------
  55. lenard@munagin.ee.mu.OZ.AU            O O
  56. lenard@mundil.cs.mu.OZ.AU             |
  57. lenard@ecr.mu.OZ.AU                \_/
  58. --
  59. Rohan Lenard
  60. lenard@munagin.ee.mu.OZ.AU
  61. lenard@mundil.cs.mu.OZ.AU
  62. lenard@ecr.mu.OZ.AU
  63.