Re: map problem, I'm not a student
From: Matthias Käppler (nospam_at_digitalraid.com)
Date: 12/07/04
- Next message: adbarnet: "Re: Best way to "redefine" a std class"
- Previous message: Victor Bazarov: "Re: ShellExecute Question"
- In reply to: Billy Patton: "Re: map problem, I'm not a student"
- Next in thread: Mike Wahler: "Re: map problem, I'm not a student"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 07 Dec 2004 21:23:41 +0100
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.)
- Next message: adbarnet: "Re: Best way to "redefine" a std class"
- Previous message: Victor Bazarov: "Re: ShellExecute Question"
- In reply to: Billy Patton: "Re: map problem, I'm not a student"
- Next in thread: Mike Wahler: "Re: map problem, I'm not a student"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|