473,854 Members | 1,612 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

map problem, I'm not a student

First, I'm not a student looking for help. Although there's nothing wrong
with studens looking for help here.
I'm learning c++ move further away from the perl wars here at
work (my version is better, use it only)

I've had this HashTable written in c that I've used for 10+ years. It works
without any problems. I'm trying to reduce my overall amount of code by using
STL in c++. To make migration easier I've create a class that inherits the map
class and made the whole thing into a template. I've kept my original function
calls to make my life easier.

Here's my efforts so far :
template <typename K,typename V> class HashTable: public std::map<K,V>
{
public:
bool Put(K&,V&,bool replace=false)
{
if (replace)
this->erase(K); <<<<<<< LINE# 79
return (this->insert(make_pa ir(K,V))) ? true : false;
}
V& Value(K&) { }
bool Keys(K&,bool firstp = false) { }
bool Exists(K&) { }
void DumpKeys(void) { }
unsigned int EntryCount(void ) { return this->size(); }
};
My test_script so far :
#include "include/HashTable.h"
#include <string>
using namespace std;
int main(void)
{
HashTable<std:: string,std::str ing> shash;
HashTable<int,i nt> ihash;
HashTable<char* ,char*> chash;

return 0;
}
The results of my compile:
[bpatton@holster 07 cdmg_toolbox]$ g++ -o x x.cxx
In file included from x.cxx:1:
include/HashTable.h: In member function `bool HashTable<K, V>::Put(K&, V&,
bool)':
include/HashTable.h:79: error: expected primary-expression before ')' token
include/HashTable.h:80: error: expected primary-expression before ',' token
include/HashTable.h:80: error: expected primary-expression before ')' token
include/HashTable.h:80: error: there are no arguments to `make_pair' that
depend on a template parameter, so a declaration of `make_pair' must be
available
include/HashTable.h:80: error: (if you use `-fpermissive', G++ will accept your
code, but allowing the use of an undeclared name is deprecated)

___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodology Group
Dallas, Texas, 214-480-4455, b-******@ti.com
Jul 22 '05 #1
9 2842
Billy Patton wrote:
First, I'm not a student looking for help. Although there's nothing
wrong with studens looking for help here.
No, there is nothing wrong, unless they just want others to do their job
for them.
I'm learning c++ move further away from the perl wars here at
work (my version is better, use it only)

I've had this HashTable written in c that I've used for 10+ years. It
works without any problems. I'm trying to reduce my overall amount of
code by using STL in c++. To make migration easier I've create a class
that inherits the map class and made the whole thing into a template.
I've kept my original function calls to make my life easier.

Here's my efforts so far :
template <typename K,typename V> class HashTable: public std::map<K,V>
{
public:
bool Put(K&,V&,bool replace=false)
bool Put(K& k, V& v, bool replace = false)
{
if (replace)
this->erase(K); <<<<<<< LINE# 79
this->erase(k);

You can't erase a type. You need a value. That's what the compiler is
suggesting ("expected primary-expression").
return (this->insert(make_pa ir(K,V))) ? true : false;
std::make_pair( k,v)

and, did you include the necessary headers? Also, I don't think that
the return value of 'insert' has conversion to 'bool' defined, you
probably want to do

return this->insert(std::ma ke_pair(k,v)).s econd;
}
V& Value(K&) { }
That is not valid C++. A function that returns V& should have at least
one 'return' statement.
bool Keys(K&,bool firstp = false) { }
Same here. Is this real code or is this a joke?
bool Exists(K&) { }
???
void DumpKeys(void) { }
unsigned int EntryCount(void ) { return this->size(); }
};
My test_script so far :
#include "include/HashTable.h"
#include <string>
using namespace std;
int main(void)
{
HashTable<std:: string,std::str ing> shash;
HashTable<int,i nt> ihash;
HashTable<char* ,char*> chash;

return 0;
}
The results of my compile:
[bpatton@holster 07 cdmg_toolbox]$ g++ -o x x.cxx
In file included from x.cxx:1:
include/HashTable.h: In member function `bool HashTable<K, V>::Put(K&,
V&, bool)':
include/HashTable.h:79: error: expected primary-expression before ')' token
include/HashTable.h:80: error: expected primary-expression before ',' token
include/HashTable.h:80: error: expected primary-expression before ')' token
include/HashTable.h:80: error: there are no arguments to `make_pair'
that depend on a template parameter, so a declaration of `make_pair'
must be available
include/HashTable.h:80: error: (if you use `-fpermissive', G++ will
accept your code, but allowing the use of an undeclared name is deprecated)


V
Jul 22 '05 #2

"Billy Patton" <bp*****@ti.com > wrote in message
news:Pi******** *************** ********@holste r07.dal.design. ti.com...
First, I'm not a student looking for help. Although there's nothing wrong
with studens looking for help here.
I'm learning c++ move further away from the perl wars here at
work (my version is better, use it only)

I've had this HashTable written in c that I've used for 10+ years. It works without any problems. I'm trying to reduce my overall amount of code by using STL in c++. To make migration easier I've create a class that inherits the map class and made the whole thing into a template. I've kept my original function calls to make my life easier.

Here's my efforts so far :
template <typename K,typename V> class HashTable: public std::map<K,V>
{
public:
bool Put(K&,V&,bool replace=false)
{
if (replace)
this->erase(K); <<<<<<< LINE# 79
'K' is a type, not an object. E.g. if 'K' is 'int',
you have:

this->erase(int);

which doesn't make much sense, does it? :-)

Perhaps you want to give names to your first two parameters
and use them.
return (this->insert(make_pa ir(K,V))) ? true : false;


Same thing here.

-Mike
Jul 22 '05 #3
"Billy Patton" <bp*****@ti.com > wrote in message
news:Pi******** *************** ********@holste r07.dal.design. ti.com...
First, I'm not a student looking for help. Although there's nothing wrong
with studens looking for help here.
I'm learning c++ move further away from the perl wars here at
work (my version is better, use it only)

I've had this HashTable written in c that I've used for 10+ years. It works without any problems. I'm trying to reduce my overall amount of code by using STL in c++. To make migration easier I've create a class that inherits the map class and made the whole thing into a template. I've kept my original function calls to make my life easier.

Here's my efforts so far :
template <typename K,typename V> class HashTable: public std::map<K,V>
{
public:
bool Put(K&,V&,bool replace=false)
{
if (replace)
this->erase(K); <<<<<<< LINE# 79
return (this->insert(make_pa ir(K,V))) ? true : false;
}
V& Value(K&) { }
bool Keys(K&,bool firstp = false) { }
bool Exists(K&) { }
void DumpKeys(void) { }
unsigned int EntryCount(void ) { return this->size(); }
};
My test_script so far :
#include "include/HashTable.h"
#include <string>
using namespace std;
int main(void)
{
HashTable<std:: string,std::str ing> shash;
HashTable<int,i nt> ihash;
HashTable<char* ,char*> chash;

return 0;
}
The results of my compile:
[bpatton@holster 07 cdmg_toolbox]$ g++ -o x x.cxx
In file included from x.cxx:1:
include/HashTable.h: In member function `bool HashTable<K, V>::Put(K&, V&,
bool)':
include/HashTable.h:79: error: expected primary-expression before ')' token include/HashTable.h:80: error: expected primary-expression before ',' token include/HashTable.h:80: error: expected primary-expression before ')' token include/HashTable.h:80: error: there are no arguments to `make_pair' that
depend on a template parameter, so a declaration of `make_pair' must be
available
include/HashTable.h:80: error: (if you use `-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)

___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodology Group
Dallas, Texas, 214-480-4455, b-******@ti.com


I think you really meant something like this:

bool Put(K& k,V& v,bool replace=false)
{
if (replace)
this->erase(k);
return (this->insert(make_pa ir(k,v))) ? true : false;
}

BTW your return expression "(this->insert(make_pa ir(k,v))) ? true : false"
is a long-winded way of saying "this->insert(make_pa ir(k,v))".

David

Jul 22 '05 #4
On Tue, 7 Dec 2004, Victor Bazarov wrote:
Billy Patton wrote:
First, I'm not a student looking for help. Although there's nothing wrong
with studens looking for help here.
No, there is nothing wrong, unless they just want others to do their job
for them.
I'm learning c++ move further away from the perl wars here at
work (my version is better, use it only)

I've had this HashTable written in c that I've used for 10+ years. It
works without any problems. I'm trying to reduce my overall amount of code
by using STL in c++. To make migration easier I've create a class that
inherits the map class and made the whole thing into a template. I've kept
my original function calls to make my life easier.

Here's my efforts so far :
template <typename K,typename V> class HashTable: public std::map<K,V>
{
public:
bool Put(K&,V&,bool replace=false)


bool Put(K& k, V& v, bool replace = false)
{
if (replace)
this->erase(K); <<<<<<< LINE# 79


this->erase(k);

You can't erase a type. You need a value. That's what the compiler is
suggesting ("expected primary-expression").
return (this->insert(make_pa ir(K,V))) ? true : false;


std::make_pair( k,v)

and, did you include the necessary headers? Also, I don't think that
the return value of 'insert' has conversion to 'bool' defined, you
probably want to do

return this->insert(std::ma ke_pair(k,v)).s econd;
}
V& Value(K&) { }


That is not valid C++. A function that returns V& should have at least
one 'return' statement.


THese are unfinished code. just have {} to make compiler happy
bool Keys(K&,bool firstp = false) { }


Same here. Is this real code or is this a joke?
bool Exists(K&) { }


???
void DumpKeys(void) { }
unsigned int EntryCount(void ) { return this->size(); }
};
My test_script so far :
#include "include/HashTable.h"
#include <string>
using namespace std;
int main(void)
{
HashTable<std:: string,std::str ing> shash;
HashTable<int,i nt> ihash;
HashTable<char* ,char*> chash;

return 0;
}
The results of my compile:
[bpatton@holster 07 cdmg_toolbox]$ g++ -o x x.cxx
In file included from x.cxx:1:
include/HashTable.h: In member function `bool HashTable<K, V>::Put(K&, V&,
bool)':
include/HashTable.h:79: error: expected primary-expression before ')' token
include/HashTable.h:80: error: expected primary-expression before ',' token
include/HashTable.h:80: error: expected primary-expression before ')' token
include/HashTable.h:80: error: there are no arguments to `make_pair' that
depend on a template parameter, so a declaration of `make_pair' must be
available
include/HashTable.h:80: error: (if you use `-fpermissive', G++ will accept
your code, but allowing the use of an undeclared name is deprecated)


V


___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodology Group
Dallas, Texas, 214-480-4455, b-******@ti.com
Jul 22 '05 #5
THanks for the assistance. I knew it had to be something simple like leveing
off the varaible.

Not to the next problem. I have:
V& Value(K& v)
{
std::map<K,V>:: iterator iter = this->find(v); <<< LINE# 23
if( iter != this->end() )
return iter->second;
return NULL;
}

THe compiler complains about :
x.cxx: In member function `V& HashTable<K, V>::Value(K&)' :
x.cxx:23: error: expected `;' before "iter"
x.cxx:24: error: `iter' undeclared (first use this function)
x.cxx:24: error: (Each undeclared identifier is reported only once for each
function it appears in.)
I pulled this almost word for word exactly from docs online.
begin
Syntax:
find
Syntax:

iterator find( const KEY_TYPE &key );

The find() function returns an iterator to key, or an iterator to the end of
the map if key is not found. For example, the following code searches a map for
a specific character and displays its associated ASCII value:

map<char,int> characterMap;

for( int i = 0; i < 26; i++ ) {
characterMap.in sert( pair<char,int>( 'A'+i, 65+i) );
characterMap.in sert( pair<char,int>( 'a'+i, 97+i) );
}

char ch;
cout << "Enter a character: ";
cin >> ch;

map<char,int>:: iterator iter = characterMap.fi nd(ch);
if( iter != characterMap.en d() ) {
cout << "ASCII value: " << iter->second << endl;
} else {
cout << "Character " << ch << " not found" << endl;
}
So what is wrong ?
___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodology Group
Dallas, Texas, 214-480-4455, b-******@ti.com
Jul 22 '05 #6
Here's what I have:
bool Keys(K& k,bool firstp = false)
{
typedef typename std::map<K,V>:: iterator map_iter;
static map_iter iter = this->begin();
if (iter EQ this->end()) return false;
k = iter->first();
++iter;
return true;
}

I had to add the typedef and the typename to get it to work.
Why?
___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodology Group
Dallas, Texas, 214-480-4455, b-******@ti.com
Jul 22 '05 #7
Billy Patton wrote:
THanks for the assistance. I knew it had to be something simple like
leveing off the varaible.

Not to the next problem. I have:
V& Value(K& v)
{
std::map<K,V>:: iterator iter = this->find(v); <<< LINE# 23
You need

typename std::map<K,V>:: iterator iter = this->find(v);

'iterator' is a dependent type. In order for the compiler to use it as it
usually would in a declaration, you need to give it a hint by using the
'typename' keyword.
if( iter != this->end() )
return iter->second;
return NULL;
}

THe compiler complains about :
x.cxx: In member function `V& HashTable<K, V>::Value(K&)' :
x.cxx:23: error: expected `;' before "iter"
x.cxx:24: error: `iter' undeclared (first use this function)
x.cxx:24: error: (Each undeclared identifier is reported only once for
each function it appears in.)
[...]


V
Jul 22 '05 #8
Billy Patton wrote:
Here's what I have:
bool Keys(K& k,bool firstp = false)
{
typedef typename std::map<K,V>:: iterator map_iter;
static map_iter iter = this->begin();
if (iter EQ this->end()) return false;
k = iter->first();
++iter;
return true;
}

I had to add the typedef and the typename to get it to work.
Why?


You didn't need that. You could simply do

typename std::map<K,V>:: iterator iter = this->begin;

BTW, you do NOT want it static, otherwise it will only be initialised
once, and next time you run, it will retain the value it got from the
previous call to 'Keys'.

V
Jul 22 '05 #9
First of all, when looking at your code, I have the impression you don't
understand what a reference is in C++. You declare your function returning
'V' references, however, on failure you return NULL.

NULL in C++ is *not* the "empty" reference. In fact in C++ there is no such
thing as a "NULL-reference". References ain't pointers. Don't confuise them
with the way Java references are handled. In C++, a reference is merely an
alias for another object. It's basically like having two names to access
the same object.
So unless you want to return references to pointers, which is certainly a
dubious practice, you're in trouble.
OTOT, Since NULL is usually defined as 0 or (void*)0, I don't even try to
imagine what will happen when you instantiate your template with an invalid
type.

Billy Patton wrote:
Not to the next problem. I have:
V& Value(K& v)
{
std::map<K,V>:: iterator iter = this->find(v); <<< LINE# 23
if( iter != this->end() )
return iter->second;
return NULL;
}

THe compiler complains about :
x.cxx: In member function `V& HashTable<K, V>::Value(K&)' :
x.cxx:23: error: expected `;' before "iter"
x.cxx:24: error: `iter' undeclared (first use this function)
x.cxx:24: error: (Each undeclared identifier is reported only once for
each function it appears in.)


Jul 22 '05 #10

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

Similar topics

3
5231
by: heroe | last post by:
Hello *, i write you with an urgent problem. I would like to create forign keys to datetime field, but it doesn't seem to work. I get Can't create table '.\sampleDB\student_module.frm' (errno: 150) error. the tables look like CREATE TABLE IF NOT EXISTS sampleDB.student ( student.from1 DATETIME not null, student.from2 DATETIME not null,
5
1172
by: 肥權 | last post by:
Hi everybody, I have a table storing the test dates, student names and the grade of the students. I am now going to find out those dates with student1 got A and student2 got B and vice versa (i.e. student1 got B and student2 got A). How can I do that? I think it is quite complicate for me. Please help. I'm using SQL server 2000. FRANKLIN
17
2359
by: Ashwin | last post by:
hi guys, i have overloaded the << operator.as shown below. ostream& operator<<(ostream &out, const student &a) { out<<a.idno; out<< " " ; // out<< a.name; out<< " " ; // out<< a.marks << endl;
1
4679
by: ryann18 | last post by:
- Modify the Student class presented in this chapter as follows. Each student object should also contain the scores for three tests. Provide a constructor that sets all instance values based on parameter values. Overload the constructor such that each test score is assumed to initially be zero. Provide a method called setTestScore that accepts two parameters: the test number (1 through 3) and the score. Also provide a method called...
21
2113
by: softwindow | last post by:
#include "stdio.h" #include "malloc.h" struct student{ int age; char *nms; struct student *next; }; struct student *create(){ int ags=0,size=sizeof(struct student); char *nms=" ";
12
3020
blackstormdragon
by: blackstormdragon | last post by:
Im having trouble with my classList variable. It's a dynamic array of strings used to store the names of the classes(my program ask for students name, number of classes, then a list of the classes). typedef char* CharPtr; class Student { public: Student& operator =(const Student& rightside); ~Student();
1
1809
by: me001 | last post by:
i know this is set up wrong but i didnt know how to do that--sorry. but this is my program that i have. it compiles and runs, but the values are completely wrong! can anyone help me?? #include <iostream> #include <iomanip> using namespace std; class Student { private: char lastname;
1
1701
by: java4life | last post by:
Java problem -------------------------------------------------------------------------------- I need to generate the following output with a TestProgram. Lecturer 65374 has 3 students: Student number 1 has name of Amanda Student number 2 has name of Patrick Student number 3 has name of Jay The Student and Lecturer classes are below.
9
2200
by: Jazi | last post by:
Hello everyone, I was wondering if someone can help me figuring out some errors I keep getting when I try to create a dll library from existing c++ code using VS2005. The issue is related to a class that returns a vector of objects. There is no errors when I compile this in c++ "linux" and it works find but the issue is with the VS2005. Here is what I have: I have two classes: student class namespace StudentClass{ ...
7
7155
by: mahdiahmadirad | last post by:
Hi dears! I wrote a simple bubble sort algorithm. it works properly when we compare full arrays but i want to sort a 2d array according to a specific part of array. it has some problem to swapping this array. please help me. my scenario: assume that we have a big 2d char array for example students for 20 persons an 30 character for each person. first 15 chars contains first name and the rest is last name. no i want to sort this array...
0
9901
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9751
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11024
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9510
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7910
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5738
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5937
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3183
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.