home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!europa.eng.gtefsd.com!emory!sol.ctr.columbia.edu!spool.mu.edu!torn!mcshub!aruba!ruby!mikea
- From: aruba!mikea@uu2.psi.com (Mike Arsenault)
- Subject: Templates with int arguments ???
- Message-ID: <1993Jan28.183021.20675@aruba.uucp>
- Sender: mikea@aruba (Mike Arsenault)
- Date: Thu, 28 Jan 1993 18:30:21 GMT
- Organization: Project Zed
- Lines: 58
-
- I'm trying to use templates with 'int' arguments as opposed to 'class'
- arguments. Here's the code.
-
- //////////// start here ///////////////////////////////////
- template <int sz>
- struct structTemplate {
- int i;
- char ch[sz];
- };
-
-
- template <int size>
- class classTemplate {
- int i;
- char * p;
- public:
- void method(const structTemplate<size> & stru);
- };
-
- template <int size>
- void classTemplate<size>::method(const structTemplate<size> & stru) { // line 18
- }
-
- main () {
- classTemplate<10> aClass;
- structTemplate<10> aStruct;
-
- aClass.method(aStruct);
- }
- //////////// end here ///////////////////////////////////
-
- and the errors I get from a simple compile such
- as 'CC -o template template.cc' (HP-UX C++ compiler v. 3.0) are:
-
- CC: "template.cc", line 18: error: template argument mismatch: expected const int f
- or formal sz, not class classTemplate <L210 > (1797)
- "template.cc", line 18: error detected during the instantiation of classTemplate<L210 >
-
- "template.cc", line 27: is the site of the instantiation
- CC: sorry, cannot recover from previous errors
-
-
- I thought there might be a problem with the multiple templates, so I
- substituted the keyword 'int' with 'class', took out the char array
- in structTemplate and instantiated the two templates in main with
- some class (String). This compiled ok.
-
- The above code was tried with Borland C++ 3.0 with no problems.
- Is this a bug with the HP compiler or is it something the sneaks
- by the Borland Compiler?
-
- Thanks in advance....
- --
- *******************************************************************************
- * Mike Arsenault |Internet Style: aruba!mikea@uu2.psi.com *
- * Systems Programming |UUCP : ...!uunet!uu2.psi.com!aruba!mikea *
- *******************************************************************************
-
-