|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Aug 2002
Messaggi: 2518
|
[c++] problema con struct
Salve a tutti,
ho il seguente metodo di una classe: Codice:
template<class K, class E>
void hash_table<K,E>::insert(const mypair<const K, E>& the_pair)
{
// search the table for a matching element
int b = search(the_pair.first);
// chack if matching element found
if (table[b] == NULL){
// no matching element and table not full
table[b] = new mypair< const K, E > (the_pair);
dsize++;
} else {
// check id duplicate or table full
if (table[b]->first == the_pair.first)
// duplicate, change table[b]->second
table[b]->second = the_pair.second;
else{
// table is full
// throw the exception hash_table_full();
}
}
}
Codice:
table[b] = new mypair< const K, E > (the_pair) Codice:
template<class K, class E>
struct mypair {
// data member
K first;
E second;
// methods
mypair(){}
mypair(mypair<const K,E>& the_pair){
first = the_pair.first;
second = the_pair.second;
}
};
Codice:
Type no matching function for call to 'mypair<const std::basic_string<char>, std::basic_string<char> >::mypair(const mypair<const std::basic_string<char>, std::basic_string<char> >&)' hash_table.h /Dizionari_2 line 184 C/C++ Problem Codice:
table[b] = new mypair< const K, E > (& the_pair) Vi ringrazio in anticipo, Guylmaster. |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Jul 2006
Città: Bergamo
Messaggi: 401
|
Prova a modificare così:
Codice:
template<class K, class E>
struct mypair {
// data member
K first;
E second;
// methods
mypair(){}
mypair(const mypair<const K,E>& the_pair){
first = the_pair.first;
second = the_pair.second;
}
};
__________________
iMac 27" 5K |
|
|
|
|
|
#3 | |
|
Senior Member
Iscritto dal: Aug 2002
Messaggi: 2518
|
Quote:
Ho parzialmente risolto togliendo tutti i const possibili ed immaginabili da quella funzione di insert, il problema è che ora mi da problemi il linker credo. Qui il nuovo codice tutto insieme http://www.ideone.com/hgl1Q e mi da i seguenti errori: Codice:
/home/aLq6T8/ccSpDBXf.o:(.rodata._ZTV10hash_tableISsiE[vtable for hash_table<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>]+0x24): undefined reference to `hash_table<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>::erase(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' /home/aLq6T8/ccSpDBXf.o:(.rodata._ZTV10hash_tableISsiE[vtable for hash_table<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>]+0x28): undefined reference to `hash_table<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>::modify(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int const&)' collect2: ld returned 1 exit status Da cosa potrebbero dipendere ora?!? |
|
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Jul 2006
Città: Bergamo
Messaggi: 401
|
Questo:
Codice:
mypair(const mypair<const K,E>& the_pair){
first = the_pair.first;
second = the_pair.second;
}
Codice:
void hash_table<K,E>::insert(const mypair<const K, E>& the_pair)
__________________
iMac 27" 5K |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 16:53.




















