By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,382 Members | 1,688 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,382 IT Pros & Developers. It's quick & easy.

STL problem.

P: n/a
#include <map>

using namespace std;

template <typename S, typename T>
void bar(void) {
map<S,T>::iterator theiter;
}

int main(void) {
return 0;
}

At the declaration of theiter, gcc (both 3.4 and 4.0) gives me:

error: expected ';' before "theiter"

Am I totally braindead or why does this not work?
Nov 2 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
hi
i use VC6 it's OK!!

cheer!

Nov 2 '05 #2

P: n/a

Todd A. Anderson wrote:
#include <map>

using namespace std;

template <typename S, typename T>
void bar(void) {
map<S,T>::iterator theiter;
}

int main(void) {
return 0;
}

At the declaration of theiter, gcc (both 3.4 and 4.0) gives me:

error: expected ';' before "theiter"

Am I totally braindead or why does this not work?

You need to use 'typename' to tell compiler iterator is a dependant
type, not a member varible of map. The following should work.
#include <map>

using namespace std;

template <typename S, typename T>
void bar(void) {
typename map<S,T>::iterator theiter;

}

int main(void) {
return 0;

}

Nov 2 '05 #3

P: n/a
"Nan Li" <na******@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...

Todd A. Anderson wrote:
#include <map>

using namespace std;

template <typename S, typename T>
void bar(void) {
map<S,T>::iterator theiter;
}

int main(void) {
return 0;
}

At the declaration of theiter, gcc (both 3.4 and 4.0) gives me:

error: expected ';' before "theiter"

Am I totally braindead or why does this not work?

You need to use 'typename' to tell compiler iterator is a dependant
type, not a member varible of map. The following should work.
#include <map>

using namespace std;

template <typename S, typename T>
void bar(void) {
typename map<S,T>::iterator theiter;

}

int main(void) {
return 0;

}


Thanks.

So who isn't compliant, VC or gcc?
Nov 2 '05 #4

P: n/a
Todd Anderson wrote:
So who isn't compliant, VC or gcc?


VC. Especially VC6.
Nov 2 '05 #5

P: n/a
On Tue, 1 Nov 2005 17:56:04 -0800, "Todd A. Anderson"
<dr******@verizon.N0SPAM.net> wrote:
#include <map>

using namespace std;

template <typename S, typename T>
void bar(void) {
map<S,T>::iterator theiter;
}

int main(void) {
return 0;
}

At the declaration of theiter, gcc (both 3.4 and 4.0) gives me:

error: expected ';' before "theiter"

Am I totally braindead or why does this not work?


As others have pointed out, you need the keyword "typename". But I
believe that gcc 3.3.2 used to issue a better error message (or was it
merely a warning?) -- something like "implicit typename is
deprecated...".

--
Bob Hairgrove
No**********@Home.com
Nov 2 '05 #6

P: n/a
use:

typename map<S,T>::iterator theiter;

Nov 2 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.