STL problem.

  • Thread starter Todd A. Anderson
  • Start date
T

Todd A. Anderson

#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?
 
N

Nan Li

Todd said:
#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;

}
 
T

Todd Anderson

Nan Li said:
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?
 
B

Bob Hairgrove

#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...".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top