473,382 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

implementing begin()

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

Sep 14 '05 #1
2 1536
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
Sep 14 '05 #2

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

Sep 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: adeleinandjeremy | last post by:
I am taking a second programming course in Java and am currently attempting to apply what I have learned using Python instead. One thing that is puzzling me is how to use an iterator. I am...
3
by: Adelein and Jeremy | last post by:
I am taking a second programming course in Java and am currently attempting to apply what I have learned using Python instead. One thing that is puzzling me is how to use an iterator. I am...
1
by: Chris B | last post by:
Does anyone know of a way in VB.net, to implement the following functionality in printing address labels. Allowing the user to select from which location on a stadard address label sheet (Avery...
2
by: Dmitri Zhukov | last post by:
Hello everyone, I am implementing software which has a medium sized number of text strings (max 100K) which are represented in a listbox. I want user to be able to search the string by typing...
27
by: Pete | last post by:
I'm doing exercise 8-2 from "Accelerated C++" where we're supposed to implement library algorithms, trying to minimize the number of iterator operations. I have two questions so far. First,...
1
by: Mana | last post by:
Hi, I want to implement nested transactions in C#. When I write BEGIN TRANSACTION inside another BEGIN TRANSACTION in an SQL Script it works fine. But when I call BeginTransaction() inside...
9
by: raylopez99 | last post by:
What's the best way of implementing a multi-node tree in C++? What I'm trying to do is traverse a tree of possible chess moves given an intial position (at the root of the tree). Since every...
3
by: Daniel Kraft | last post by:
Hi, I usually program in C++, but for a special project I do have to code in C (because it may be ported to embedded-like platforms where no C++ compiler exists). I do want to realize some...
4
by: Kenneth Porter | last post by:
Can someone point me to documentation or examples on how to implement an Enumerable interface in C++/CLI? I've found examples for C# but nothing for C++. I'm wrapping a native library that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.