473,327 Members | 1,979 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,327 software developers and data experts.

HashTable again

I've had a lot of help, but I need a little more.

Here's a snippett of code:
template <typename K,typename V>
class HashTable : private std::map<K, V>
{
private:

public:
bool Keys(K& key, bool firstp = false) const
{
static typename std::map<K,V>::iterator map_iter;
if (firstp) map_iter = this->begin(); <<<<<<<<<<<<LINE #81
if (map_iter == this->end()) return false;
key = map_iter->first;
++map_iter;
return true;
}
I need to call this method until it has hit all the keys. Thst's why I declare
map_iter as static.
HashTable<int,std::string> h;
int i;
bool first=true;
while (h.Keys(i,first))
{
first = false;
do_something_with_i();
}

Here's my actual test code:
void t_HashTable(void)
{
ENTER
HashTable<int,std::string> h;
pass(0 EQ h.EntryCount() , "verify hash is empty");
pass(true EQ h.Put(1,"a") , "put a into 1");
pass(1 EQ h.EntryCount() , "verify hash hasn 1 entry");
pass(h.Value(1) EQ "a" , "Verify value of 1 is a");
int i;
pass(h.Keys(i,true) , "Get first key"); <<<<<<< LINE# 142
pass(i EQ 1 , "Verify only key is 1");

LEAVE
}
Here's my compiler message:
x.cxx: In member function `bool HashTable<K, V>::Keys(K&, bool) const [with K =
int, V = std::string]':
x.cxx:142: instantiated from here
x.cxx:81: error: no match for 'operator=' in 'map_iter = ((const std::map<int,
std::string, std::less<int>, std::allocator<std::pair<const int, std::string> >
*)((const HashTable<int, std::string>*)this))->std::map<_Key, _Tp, _Compare, _Alloc>::begin [with _Key = int, _Tp = std::string, _Compare = std::less<int>,
_Alloc = std::allocator<std::pair<const int, std::string> >]()'
/apps/gcc/3.4.1/lib/gcc/i686-pc-linux-gnu/3.4.1/../../../../include/c++/3.4.1/bits/stl_tree.h:152:
note: candidates are: std::_Rb_tree_iterator<std::pair<const int, std::string>& std::_Rb_tree_iterator<std::pair<const int, std::string> >::operator=(const

std::_Rb_tree_iterator<std::pair<const int, std::string> >&)

___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodology Group
Dallas, Texas, 214-480-4455, b-******@ti.com
Jul 22 '05 #1
2 3606
Billy Patton wrote:
I've had a lot of help, but I need a little more.

Here's a snippett of code:
template <typename K,typename V>
class HashTable : private std::map<K, V>
{
private:

public:
bool Keys(K& key, bool firstp = false) const
{
static typename std::map<K,V>::iterator map_iter;
if (firstp) map_iter = this->begin(); <<<<<<<<<<<<LINE #81
Since 'Keys' is a const function, only a const 'begin' can be called.
The const 'begin' returns 'const_iterator' value, not 'iterator'.
Declare your 'map_iter' like this:

static typename std::map<K,V>::const_iterator map_iter;
if (map_iter == this->end()) return false;
key = map_iter->first;
++map_iter;
return true;
}
[...]

Jul 22 '05 #2
Billy Patton wrote:

I've had a lot of help, but I need a little more.

In addition to Victor's help:

What you are trying to do is an extremely bad idea.
It prevents the user of this class to have 2 HashTable
objects and iterate through them at the same time. Why?
Simple: Because there is only *1* iteration variable when
2 are needed.
--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #3

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

Similar topics

3
by: shine | last post by:
I am trying to add an integer array to a hashtable. While adding to hashtable I want to check the duplicates in array, the way I want to do is add the key(the integer stored in array) if a...
7
by: davidw | last post by:
I always use NameValueCollection. But I read an article says the only differece between Hashtable and NameValueCollection is that NameValueCollection could accept more than one value with same key?...
5
by: francois | last post by:
First of all I would to to apologize for resending this post again but I feel like my last post as been spoiled Here I go for my problem: Hi, I have a webservice that I am using and I would...
7
by: Joseph Lee | last post by:
Hi All, I am having problem when i am using hashtable to keep an array of bytes value as keys. Take a look at the code snippet below --------------------------------------------------- ...
33
by: Ken | last post by:
I have a C# Program where multiple threads will operate on a same Hashtable. This Hashtable is synchronized by using Hashtable.Synchronized(myHashtable) method, so no further Lock statements are...
8
by: Robin Tucker | last post by:
When I create a hashtable hashing on Object-->Item, can I mix "string" and "integer" as the key types? I have a single thumbnail cache for a database with (hashed on key) and a file view (hashed...
7
by: J L | last post by:
I have defined a structure private structure FieldInfo dim FieldName as string dim OrdinalPostioin as Integer dim DataType as Type dim Size as Integer end structure I read this information...
9
by: Nick Vaughan | last post by:
While running some long term tests on our Broadcast SDK one of our thread dropped out because an exception had been thrown: Exception: System.ArgumentOutOfRangeException Message: Load factor...
3
by: Manish | last post by:
Hi m not able to convert the node values of a XML file to Hashtable Actaully i need to traverse the XML Nodes again and again and want to pick values on filters what i want is to stroe the...
2
by: Bruce | last post by:
Hi I am having a problem understanding the exact advantages of using an ArrayList over a Hashtable in any situation. In most areas of an application I am working on, lookup needs to be fast. If I...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.