On Thu, Sep 18, 2003 at 08:36:14PM +0000, Steven Keuchel wrote: > Mailing-List: contact gcc-help-help@xxxxxxxxxxx; run by ezmlm > Precedence: bulk > List-Unsubscribe: <mailto:gcc-help-unsubscribe-O.Kullmann=swansea.ac.uk@xxxxxxxxxxx> > List-Archive: <http://gcc.gnu.org/ml/gcc-help/> > List-Post: <mailto:gcc-help@xxxxxxxxxxx> > List-Help: <mailto:gcc-help-help@xxxxxxxxxxx> > Delivered-To: mailing list gcc-help@xxxxxxxxxxx > From: Steven Keuchel <steven.keuchel@xxxxxxxxxx> > To: gcc-help@xxxxxxxxxxx > Date: Thu, 18 Sep 2003 20:36:14 +0000 > User-Agent: KMail/1.5.3 > X-SA-Exim-Mail-From: gcc-help-return-13929-O.Kullmann=swansea.ac.uk@xxxxxxxxxxx > Subject: using the member types of a parameter class in a template function > X-Spam-Checker-Version: SpamAssassin 2.60-rc1 (1.197-2003-08-21-exp) on exim > X-Spam-Level: > X-Spam-Status: No, hits=0.0 required=5.5 tests=none autolearn=no version=2.60-rc1 > X-SA-Exim-Version: 3.1 (built Fri Aug 22 12:30:01 GMT 2003) > X-UIDL: "^J!!3W9"!EX~!!MN="! > > 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 <vector> > 02: > 03: template<class CONT> 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<int> myvec; > 11: templfunc(myvec); > 12: > 13: return 0; > 14: } > Hi, the above code is not correct C++-code: The type CONT::iterator is a *dependent type*, and the keyworde "typename" must be used, that is, line 05 must be: 05: typename CONT::iterator myiter; Oliver