From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26317 invoked by alias); 18 Sep 2003 19:08:10 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 26310 invoked from network); 18 Sep 2003 19:08:08 -0000 Received: from unknown (HELO mail-srv2.micron.com) (137.201.242.130) by sources.redhat.com with SMTP; 18 Sep 2003 19:08:08 -0000 Received: from mail-srv2.micron.com (localhost [127.0.0.1]) by mail-srv2.micron.com (8.12.9/8.12.2) with ESMTP id h8IJ89RS016035 for ; Thu, 18 Sep 2003 13:08:10 -0600 (MDT) Received: from ntxboimbx07.micron.com (ntxboimbx07.micron.com [137.201.80.94]) by mail-srv2.micron.com (8.12.9/8.12.2) with ESMTP id h8IJ88a3016024; Thu, 18 Sep 2003 13:08:09 -0600 (MDT) From: lrtaylor@micron.com X-MimeOLE: Produced By Microsoft Exchange V6.0.6375.0 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: using the member types of a parameter class in a template function Date: Thu, 18 Sep 2003 19:08:00 -0000 Message-ID: <363801FFD7B74240A329CEC3F7FE4CC40D3367@ntxboimbx07.micron.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: To: , X-Scanned-By: MIMEDefang 2.33 (www . roaringpenguin . com / mimedefang) X-SW-Source: 2003-09/txt/msg00215.txt.bz2 Hello, I believe your code should be like this: 01: #include 02: 03: template void templfunc(const CONT& mycont) 04: { 05: typename CONT::iterator myiter; // and now do sth with it 06: } 07: 08: int main(int argc, char **argv) 09: { 10: std::vector myvec; 11: templfunc(myvec); 12: 13: return 0; 14: } Note that I have added "typename" to line 5. I believe that using "typenam= e" here adheres to the ANSI standard. It just may be that MS has decided t= o make it optional in their compiler. This compiles with GCC 3.3.1. I sus= pect it will with 3.2.3 as well, but I can't test that. In addition, you will probably want/need to use a const_iterator rather tha= n an iterator since you're passing in a const reference as your parameter... Thanks, Lyle Taylor -----Original Message----- From: Steven Keuchel [mailto:steven.keuchel@freenet.de] Sent: Thursday, September 18, 2003 2:36 PM To: gcc-help@gcc.gnu.org Subject: using the member types of a parameter class in a template function Hi list, i'm posting to this list instead of comp.lang.c++ because the following code compiles with M$VC 7.0 but not with GCC. I want to write a function that gets an arbitrary container and iterates through it. I can access the member funcs of the passed object and even static member functions of the parameter class (if it has some) but not member types of the class. 01: #include 02: 03: template void templfunc(const CONT& mycont) 04: { 05: CONT::iterator myiter; // and now do sth with it 06: } 07: 08: int main(int argc, char **argv) 09: { 10: std::vector myvec; 11: templfunc(myvec); 12: 13: return 0; 14: } I know that i can implement this function by passing the range using 2 iterators, which would be better code, but that's not the solution i search for. gcc 3.2.3 says: main.cpp:5: syntax error before `;' token gcc 3.4 (20030910) says: main.cpp: In function `void templfunc(const CONT&)': main.cpp:5: error: expected `;' main.cpp: In function `void templfunc(const CONT&) [with CONT =3D std::vector >]': main.cpp:11: instantiated from here main.cpp:5: error: `CONT::iterator' names a type, but a non-type is expected Is this a GCC bug or is my code faulty and there's yet another bug in M$VC ? Best regards, Steven. PS.: please CC me, as i'm not subscribed to the list, thx