This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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




****************************************

IMPORTANT INFORMATION
The information contained in this email or any of its attachments is confidential and is intended for the exclusive use of the individual or entity to whom it is addressed. It may not be disclosed to, copied, distributed or used by anyone else without our express permission. If you receive this communication in error please advise the sender immediately and delete it from your systems.  This email is not intended to and does not create legally binding commitments or obligations on behalf of Hornbill Systems which may only be created by hard copy writing signed by a director or other authorized officer.  Any opinions, conclusions and other information in this message that do not relate to the official business of Hornbill Systems Limited are unauthorized and neither given nor endorsed by it. Although Anti-Virus measures are used by Hornbill Systems it is the responsibility of the addressee to scan this email and any attachments for computer viruses or other defects. Hornbill Systems does not accept any liability for any loss or damage of any nature, however caused, which may result directly or indirectly from this email or any file attached.

Hornbill Systems Limited. Registered Office: Ares, Odyssey Business Park, West End Road, Ruislip, HA4 6QD, United Kingdom. Registered in England Number: 3033585

****************************************

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]