RE: error: 'cit' was not declared in this scope

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I am trying to port some code from VC9 to Linux using "gcc (Ubuntu 4.4.1-4ubuntu8) 4.4.1" and I am getting an error with GCC that I don't get when compiling under VC9.

test.cpp: In member function 'const Value& enums_map<Key, Value>::operator[](const Key&) const':
test.cpp:30: error: expected ';' before 'cit'
test.cpp:31: error: 'cit' was not declared in this scope

The problem is I need to create a local variable of type <the base class>::const_iterator but I cant work out how I can do this. As I mentioned, the code below works when compiling under VC9 but not with g++. I can't work out how to solve this problem, could anyone help? This is the code sample (just compiling with "g++ test.cpp"

---------------------------------<snip>-------------------------------------
#include <stdio.h>
#include <string>
#include <iostream>
#include <tr1/regex>
#include <inttypes.h>
#include <stdarg.h>

#include <map>


// Just the std::map, plus a const version of operator[] which returns a const reference to a const member template<typename Key, typename Value> class enums_map : public std::map<Key, Value> {
       typedef std::map<Key, Value> base_type;

public:
       enums_map()
               : default_value_()
       {
       }

       enums_map(const Value& default_value)
               : default_value_(default_value)
       {
       }

       const Value& operator[] (const Key& key) const
       {
               base_type::const_iterator cit = base_type::find(key);
               if (cit == base_type::end())
                       return default_value_;
               else
                       return cit->second;
       }

       using base_type::operator[];

private:
       const Value default_value_;
};
---------------------------------<snip>-------------------------------------

Any help very much appreciated

Thanks,

Gerry




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux