home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 20087 < prev    next >
Encoding:
Text File  |  1993-01-28  |  2.2 KB  |  69 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!europa.eng.gtefsd.com!emory!sol.ctr.columbia.edu!spool.mu.edu!torn!mcshub!aruba!ruby!mikea
  3. From: aruba!mikea@uu2.psi.com (Mike Arsenault)
  4. Subject: Templates with int arguments ???
  5. Message-ID: <1993Jan28.183021.20675@aruba.uucp>
  6. Sender: mikea@aruba (Mike Arsenault)
  7. Date: Thu, 28 Jan 1993 18:30:21 GMT
  8. Organization: Project Zed
  9. Lines: 58
  10.  
  11. I'm trying to use templates with 'int' arguments as opposed to 'class'
  12. arguments. Here's the code.
  13.  
  14. //////////// start here ///////////////////////////////////
  15. template <int sz>
  16. struct structTemplate {
  17. int i;
  18. char ch[sz];
  19. };
  20.  
  21.  
  22. template <int size> 
  23. class classTemplate {
  24.     int i;
  25.     char * p;
  26. public:
  27.     void method(const structTemplate<size> & stru);
  28. };
  29.  
  30. template <int size> 
  31. void classTemplate<size>::method(const structTemplate<size> & stru) {  // line 18
  32. }
  33.  
  34. main () {
  35.     classTemplate<10> aClass;
  36.     structTemplate<10> aStruct;
  37.  
  38.     aClass.method(aStruct);
  39. }
  40. //////////// end here ///////////////////////////////////
  41.  
  42. and the errors I get from a simple compile such
  43. as 'CC -o template template.cc' (HP-UX C++ compiler v. 3.0) are:
  44.  
  45. CC: "template.cc", line 18: error: template argument mismatch: expected  const int  f
  46. or formal  sz, not  class classTemplate <L210 >  (1797)
  47. "template.cc", line 18:          error detected during the instantiation of classTemplate<L210 >
  48.  
  49.  "template.cc", line 27:         is the site of the instantiation
  50.   CC: sorry, cannot recover from previous errors
  51.  
  52.  
  53. I thought there might be a problem with the multiple templates, so I
  54. substituted the keyword 'int' with 'class', took out the char array
  55. in structTemplate and instantiated the two templates in main with
  56. some class (String). This compiled ok.
  57.  
  58. The above code was tried with Borland C++ 3.0 with no problems.
  59. Is this a bug with the HP compiler or is it something the sneaks
  60. by the Borland Compiler?
  61.  
  62. Thanks in advance....
  63. -- 
  64. *******************************************************************************
  65. * Mike Arsenault                |Internet Style: aruba!mikea@uu2.psi.com      *
  66. * Systems Programming           |UUCP     : ...!uunet!uu2.psi.com!aruba!mikea *
  67. *******************************************************************************
  68.  
  69.