On Thu, 15 Sep 2005 21:32:40 +0200, Mogens Hansen wrote:
>> Har du tilpasset
>> din løsning til min template
>
> Nej - men det burde ikke spille nogen rolle.
>
Det var en typo, der skulle have stået: Har nu ...
>
> Hvis det hjælper, så ja.
>
Giver præcis samme fejl!
Prøvede lige:
loke
/Projects/hashing/src$ gcc-3.2 -I../include main.cc testdata.o
gcc-3.2: installation problem, cannot exec `cc1plus': No such file or directory
loke
/Projects/hashing/src$ gcc-2.95 -I../include main.cc testdata.o
.../include/hashtable.h: In method `class vector<int,allocator<int> > hashtable<int>::gethashtable() const':
main.cc:122: instantiated from here
.../include/hashtable.h:121: assignment to `set<int,less<int>,allocator<int> > *' from `const set<int,less<int>,allocator<int> > *' discards qualifiers
og
loke
/Projects/hashing/src$ gcc-3.3 -I../include main.cc testdata.o
In file included from main.cc:26:
.../include/hashtable.h: In member function `std::vector<Object,
std::allocator<_CharT> > hashtable<Object>::gethashtable() const':
.../include/hashtable.h:119: warning: `std::vector<std::set<Object,
std::less<_Key>, std::allocator<_CharT> >, std::allocator<std::set<Object,
std::less<_Key>, std::allocator<_CharT> > > >::iterator' is implicitly a
typename
.../include/hashtable.h:119: warning: implicit typename is deprecated, please
see the documentation for details
/usr/include/c++/3.3/bits/stl_iterator.h: In constructor `
__gnu_cxx::__normal_iterator<_Iterator, _Container>::__normal_iterator(const
__gnu_cxx::__normal_iterator<_Iter, _Container>&) [with _Iter = const
std::set<int, std::less<int>, std::allocator<int> >*, _Iterator =
std::set<int, std::less<int>, std::allocator<int> >*, _Container =
std::vector<std::set<int, std::less<int>, std::allocator<int> >,
std::allocator<std::set<int, std::less<int>, std::allocator<int> > > >]':
.../include/hashtable.h:121: instantiated from `std::vector<Object, std::allocator<_CharT> > hashtable<Object>::gethashtable() const [with Object = int]'
main.cc:122: instantiated from here
/usr/include/c++/3.3/bits/stl_iterator.h:598: error: invalid conversion from `
const std::set<int, std::less<int>, std::allocator<int> >* const' to `
std::set<int, std::less<int>, std::allocator<int> >*'
Denne fejlmeddelelse ser interessant ud. Først warning om at implicit
typename er deprecated
Åbenbart har andre samme problemer:
http://gcc.gnu.org/ml/gcc-help/2004-10/msg00179.html
Det ser ud til, at compileren ikke kan lide templates i denne situation.
Udskifter jeg Object med int, char eller string giver compileren ingen
fejl. Burde det ikke være muligt, at have en template refence i en vector
erklæring?
Min insert og find metode anvender det, og her giver det ingen problemer:
const void insert(const Object& input){
unsigned int position;
position=hash(input);
std::set<Object>& bucket=buckets[position];
bucket.insert(input);
}
const bool find(const Object& input)const{
unsigned int position;
position=hash(input);
const std::set<Object>& bucket=buckets[position];
bool retVal = (bucket.find(input)!=bucket.end());
return retVal;
}
--
Hilsen/Regards
Michael Rasmussen
http://keyserver.veridis.com:11371/pks/lookup?op=get&search=0xE3E80917