Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > implementing begin()

Reply
Thread Tools

implementing begin()

 
 
Nick Keighley
Guest
Posts: n/a
 
      09-14-2005
Hi,

I'm trying to iterate over a container class. The class actually
contains a std::map, so I thought all I'd have to implement begin() and
end().

The example code has a problem in begin()

#include <string>
#include <map>

using namespace std;

class Inventory
{
public:
typedef map<string,string>::iterator iterator;

map<string,string>::iterator& begin()
{ return map_.begin(); } // *** ERROR HERE

private:
map<string,string> map_;
};

void f (string s)
{
}

int main (void)
{
Inventory invent;
Inventory::iterator i;

i = invent.begin();

return 0;
}



I can post the full text of the error message but it is rather
long. But in essense it says "cannot convert std::map...begin() to
std::_Rb_tree_iterator..."

I'm using gcc with the bloodshed environment.

Any suggestions greatfully accepted!


--
Nick Keighley

"Half-assed programming was a time-filler that, like knitting,
must date to the beginning of human experience."
"A Fire Upon The Deep" by Verne Vinge

 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      09-14-2005
Nick Keighley wrote:

> #include <string>
> #include <map>
>
> using namespace std;
>
> class Inventory
> {
> public:
> typedef map<string,string>::iterator iterator;
>
> map<string,string>::iterator& begin()


Make that:

map<string,string>::iterator begin()

> { return map_.begin(); } // *** ERROR HERE
>
> private:
> map<string,string> map_;
> };
>
> void f (string s)
> {
> }
>
> int main (void)
> {
> Inventory invent;
> Inventory::iterator i;
>
> i = invent.begin();
>
> return 0;
> }



Best

Kai-Uwe Bux
 
Reply With Quote
 
 
 
 
Nick Keighley
Guest
Posts: n/a
 
      09-14-2005

Kai-Uwe Bux wrote:
> Nick Keighley wrote:


<snip>

> >
> > map<string,string>::iterator& begin()

>
> Make that:
>
> map<string,string>::iterator begin()
>
> > { return map_.begin(); } // *** ERROR HERE


<snip>

yes! thankyou!


--
Nick Keighley

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Implementing Interface Gomathi ASP .Net 1 11-17-2005 03:09 PM
Need help implementing a proj on SPARTAN3 Riccardo Fregonese VHDL 2 01-03-2005 01:21 PM
Implementing the CORDIC algorithm without using Real Data Type Johnsy Joseph VHDL 2 10-29-2004 10:49 AM
Implementing E1 - E3 Dev VHDL 1 09-09-2004 09:06 AM
vhdl for implementing pre-fetch and an instruction cache Eqbal Z VHDL 3 11-16-2003 06:07 AM



Advertisments