views:

40

answers:

3

the following code says error: expected ‘;’ before ‘forwit’ error: expected ‘;’ before ‘revit’

template<class T>
class mapping {

public:
    map<T,int> forw;
    map<int,T> rev;
    int curr;
    //typeof(forw)::iterator temp;
    map<T,int>::iterator forwit;
    map<int,T>::iterator revit;
};

//    }; // JVC: This was present, but unmatched.

i have completely no idea what the problem is? please help.

thanks in advance

+5  A: 

To help the compiler understand you are talking about a type in a templated context, you have to help it writing typename.

In your case

typename map<T,int>::iterator forwit;
Scharron
yes it works. Thanks a lot
mukul
@mukul: If this answer solved your problem(s) (and it seems it did), you should **accept it**. This is how StackOverflow works.
ereOn
I was waiting for the timer to complete. It was saying something like 7 more mins to accept an answer.
mukul
Just a simple question. If all the answers satisfy you equally and solved my problem, then how to accept the one. Should i accept the earliest replied or what. is there some way of paying back gratitude to show yes this user provides very precise answers.
mukul
To reward all answers, just vote for it.The accepted answer is for people looking for the same answer. You should take the most precise one (for example with interesting comments).
Scharron
A: 

You have to tell the compiler map<T,int>::iterator is a type by the typename keyword.

typename map<T,int>::iterator forwit;
jpalecek
thanks it works
mukul
+1  A: 

Add typename:

typename map<T,int>::iterator forwit;
typename map<int,T>::iterator revit;

Since map<T,int> depends on the template parameter, it isn't known until the template is instantiated whether iterator is a type or a static member; unless you use typename to specify that it is a type, the compiler will assume the latter.

Mike Seymour