From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12074 invoked by alias); 29 Dec 2009 19:49:05 -0000 Received: (qmail 12060 invoked by uid 22791); 29 Dec 2009 19:49:04 -0000 X-SWARE-Spam-Status: No, hits=2.2 required=5.0 tests=AWL,BAYES_00,BOTNET,SPF_PASS X-Spam-Check-By: sourceware.org Received: from vms173003pub.verizon.net (HELO vms173003pub.verizon.net) (206.46.173.3) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 29 Dec 2009 19:48:59 +0000 Received: from [10.10.1.168] ([209.190.166.162]) by vms173003.mailsrvcs.net (Sun Java(tm) System Messaging Server 6.3-7.04 (built Sep 26 2008; 32bit)) with ESMTPA id <0KVF00HA2J171COB@vms173003.mailsrvcs.net> for gcc-help@gcc.gnu.org; Tue, 29 Dec 2009 13:48:43 -0600 (CST) Message-id: <4B3A5D4B.2020006@verizon.net> Date: Tue, 29 Dec 2009 20:45:00 -0000 From: "John S. Fine" User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-version: 1.0 To: Gerry Sweeney Cc: gcc-help@gcc.gnu.org Subject: Re: error: 'cit' was not declared in this scope References: In-reply-to: Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2009-12/txt/msg00365.txt.bz2 You are focusing on the second error, but that was just a consequence of the first. During the initial parsing, the compiler doesn't know that types from the base class are types, because it doesn't know what the base class will be until it has the template actuals. You can tell it that types are types using the typename keyword in each place where you use them. I think that is a bad style, and it is better to bring such types into the current class with a typedef as in typedef std::map base_type; typedef typename base_type::const_iterator const_iterator; ... const_iterator cit = base_type::find(key); But in similar style, I also think "using" is better than individual overrides for functions that should be inherited from the base class: typedef std::map base_type; typedef typename base_type::const_iterator const_iterator; using base_type::find; ... const_iterator cit = find(key); Gerry Sweeney wrote: > 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 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 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" > > ---------------------------------------------------------------------- > > #include > #include > #include > #include > #include > #include > > #include > > > // Just the std::map, plus a const version of operator[] which returns > a const reference to a const member template Value> class enums_map : public std::map { > typedef std::map 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_; > }; > ---------------------------------------------------------------------- > > > Any help very much appreciated > > Thanks, > > Gerry > > > >