Looping through template objects in map

can some one help me to get this code working

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
template <typename T>
class Dummy
{
  // Implementation
};

template <typename T>
class SomeClass
{
Private:
    map<char, Dummy<T>* > dummymap;
   
public:
   void process()
   for(map<char, Dummy<T>* >::iterator iter = dummymap.begin(); iter = dummymap.end(); ++iter;
  {
     //I want to iterate through all elements;
      iter->second->process();
  }
}




Last edited on
I think you're missing curly braces around the function definition from lines 15 to 19, but what exactly are you trying to do here?
You have blatant syntax errors. Lets ignore those and assume that you can fix them.

The type of the iterator will make the compiler say a lot. There is an easy way around that in C++11: auto.

The end condition of the for loop. Assignment is not the correct operator there.

Line 18 requires that Dummy's implementation has public process()
Last edited on
here is the updated code..
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
template <typename Type=short>
class some_obj
{
   private:
	Type val1;

   public:
   some_obj(val = 0) : val1(val) {}


   void updatevalue(Type value)
   {
      val1 = value;
   }
   
};


class container_obj
{

   private:
      typedef enum
      {
         Property_1,
         property_2
      } property

      map<property, some_obj*> container;


      
      some_obj<short> *first_prop;
      some_obj<short> *second_prop;

   public:
      container_obj()
      {
         this->first_prop; = new some_obj<>();
         this->second_prop = new some_obj<>();

         this->container.insert(make_pair(Property_1, this->first_prop));
         this->container.insert(make_pair(Property_2, this->second_prop));
      }

      ~container_obj()
      {
         delete this->first_prop;
         delete this->second_prop;
      }

      void processUpdate(short value)
      {
         this->first_prop->update(value);  //Syntax error expecting >
	 this->second_prop->update(value); //same error
      }

}; 
That is rather obvious.
The type of first_prop is some_obj<short>* and therefore
the first_prop->update(value) is calling the member function update(short) of
object that has type some_obj<short>.

Your some_obj template has no member update(). It does have updateValue() though ...


However, why the pointers? You already have the map.
Why the map? There is no dynamic mapping; the code so far is quite static.
Topic archived. No new replies allowed.