advance problem 03

closed account (28poGNh0)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# include <iostream>
# include <map>
using namespace std;

template<class T,class T2>
class c_map
{
    map<T,T2> classMap;
    map<T,T2>::iterator iter;

    public:
        c_map(map<T,T2> &tmpMap){classMap = tmpMap;}

        void showMap(void)
        {
            for(iter = classMap.begin() ;iter != classMap.end() ;iter++)
            {
                cout << iter->first << " " << iter->second << endl;
            }

        }
};

int main()
{
    map<int,int> myMap;

    myMap.insert(pair<int,int>(1,2));
    myMap.insert(pair<int,int>(3,4));
    myMap.insert(pair<int,int>(5,6));

    c_map<int,int> firstC(myMap);
    firstC.showMap();

    return 0;
}


Whats wrong with this line map<T,T2>::iterator iter;

also I declared iter as private but It is not recongized in showMap function

Thanks a lot for reading
Last edited on
Whats wrong with this line map<T,T2>::iterator iter;


What makes you think something is wrong with it? Do you get a compiler error? If yes, what's the error?
closed account (28poGNh0)
I am using code::blocks that does not support c++11

Those are the errors

C:\Documents and Settings\Techno01\Bureau\myProject\main.cpp|9|error: type 'std::map<T, T2, std::less<_Key>, std::allocator<std::pair<const _Key, _Tp> > >' is not derived from type 'c_map<T, T2>'|

C:\Documents and Settings\Techno01\Bureau\myProject\main.cpp|9|error: expected ';' before 'iter'|

C:\Documents and Settings\Techno01\Bureau\myProject\main.cpp||In member function 'void c_map<T, T2>::showMap()':|

C:\Documents and Settings\Techno01\Bureau\myProject\main.cpp|16|error: 'iter' was not declared in this scope|
||=== Build finished: 3 errors, 0 warnings ===|


Thanks again
need typename before ‘std::map<T, T2>::iterator’ because ‘std::map<T, T2>’ is a dependent scope
http://www.parashift.com/c++-faq-lite/nondependent-name-lookup-types.html


¿why is an iterator a member of your class?
you should limit the scope of your variables
Last edited on
closed account (28poGNh0)
Well That's what I am looking for ,Thanks alot @ne555, you're awsome,

well, It is been a long day I hope the world rest in peace
Topic archived. No new replies allowed.