This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
using the member types of a parameter class in a template function
- From: Steven Keuchel <steven dot keuchel at freenet dot de>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 18 Sep 2003 20:36:14 +0000
- 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 <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: }
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 =
std::vector<int, std::allocator<int> >]':
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