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

  1. Xref: sparky comp.lang.c++:16438 gnu.g++.help:1447
  2. Newsgroups: comp.lang.c++,gnu.g++.help
  3. Path: sparky!uunet!ukma!wupost!sdd.hp.com!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 (again)
  6. Message-ID: <lenard.722028048@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 19:20:48 GMT
  11. Lines: 55
  12.  
  13. Whoops I made a mistake in my last post regarding templates under g++/gcc.
  14. Here is a repost with the correction made (and hightlighted) -
  15.  
  16. I have a question regarding template and g++/gcc.
  17. According to the ARM something like this should be valid -
  18.  
  19. >    template<class T,char *V> class foo : public T
  20.                         ^^^^^^^^^^
  21. >    {
  22. >        foo(char *filename = V) {} ;
  23. >    }
  24. ...
  25. >    foo<int,"Hello">    a;
  26.  
  27. However g++/gcc (2.2.2) complains pretty mightily about it.
  28. I have tried something like this -
  29.  
  30. >    class A
  31. >    {
  32. >        const char *str = "Hello";
  33. >        operator char * () const { return str; }
  34. >    }
  35. >    template<class T,class V> class foo : public T
  36.                         ^^^^^^^^^^
  37. >    {
  38. >        foo(char *filename = (char *)V) {} ;
  39. >    }
  40. >
  41. >    foo<int,A>        a;
  42.  
  43. and it can be made to work, but it is not as elegant.
  44.  
  45. Does anyone have a work around so that I can use something like the first
  46. example ? (NOTE: I may not have my code syntactically correct, as I am trying
  47. to remember it from a few days ago at a friends work, but I assume you get the
  48. idea)
  49.  
  50. Any help would be appreciated.
  51.  
  52. As an aside (sp?), the examples in the ARM for this sort of template class
  53. both work - did GNU only use these or what :-) ?
  54.  
  55.  
  56. Thanks in advance,
  57. Regards,
  58.     Rohan
  59. --------------------------------------------------------------------------
  60. lenard@munagin.ee.mu.OZ.AU            O O
  61. lenard@mundil.cs.mu.OZ.AU             |
  62. lenard@ecr.mu.OZ.AU                \_/
  63. --
  64. Rohan Lenard
  65. lenard@munagin.ee.mu.OZ.AU
  66. lenard@mundil.cs.mu.OZ.AU
  67. lenard@ecr.mu.OZ.AU
  68.