472,353 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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_pair(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::string> shash;
HashTable<int,int> ihash;
HashTable<char*,char*> chash;

return 0;
}
The results of my compile:
[bpatton@holster07 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 2736
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_pair(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::make_pair(k,v)).second;
}
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::string> shash;
HashTable<int,int> ihash;
HashTable<char*,char*> chash;

return 0;
}
The results of my compile:
[bpatton@holster07 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*******************************@holster07.d al.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_pair(K,V))) ? true : false;


Same thing here.

-Mike
Jul 22 '05 #3
"Billy Patton" <bp*****@ti.com> wrote in message
news:Pi*******************************@holster07.d al.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_pair(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::string> shash;
HashTable<int,int> ihash;
HashTable<char*,char*> chash;

return 0;
}
The results of my compile:
[bpatton@holster07 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_pair(k,v))) ? true : false;
}

BTW your return expression "(this->insert(make_pair(k,v))) ? true : false"
is a long-winded way of saying "this->insert(make_pair(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_pair(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::make_pair(k,v)).second;
}
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::string> shash;
HashTable<int,int> ihash;
HashTable<char*,char*> chash;

return 0;
}
The results of my compile:
[bpatton@holster07 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.insert( pair<char,int>('A'+i, 65+i) );
characterMap.insert( pair<char,int>('a'+i, 97+i) );
}

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

map<char,int>::iterator iter = characterMap.find(ch);
if( iter != characterMap.end() ) {
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
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...
5
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...
17
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<< " " ; // ...
1
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...
21
by: softwindow | last post by:
#include "stdio.h" #include "malloc.h" struct student{ int age; char *nms; struct student *next; }; struct student *create(){ int...
12
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...
1
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...
1
by: java4life | last post by:
Java problem -------------------------------------------------------------------------------- I need to generate the following output with a...
9
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...
7
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...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

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.