assign mit verschachtelten datentypen
-
folgende zuweisung benutze ich in meinem programm um eine matrix mit listen als elementen zu erzeugen:
[/cpp]
rawdata.assign(300,vector<list<int> >(20,0));
[cpp]bis jetzt ging das auch wunderbar, wenn ich nicht total bekloppt bin. seitdem ich aber opensuse 11 mit gcc-g++ 4.3-39.1 installiert habe kommt beim compilieren die fehlermeldung:
[/code]
/usr/include/c++/4.3/bits/stl_vector.h: In member function ‘void std::vector<_Tp, _Alloc>::_M_initialize_dispatch(_Integer, _Integer, std::__true_type) [with _Integer = int, _Tp =std::list<int, std::allocator<int> >, _Alloc = std::allocator<std::list<int, std::allocator<int> > >]’:
/usr/include/c++/4.3/bits/stl_vector.h:290: instantiated from ‘std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const _Alloc&) [with _InputIterator = int, _Tp = std::list<int, std::allocator<int> >, _Alloc = std::allocator<std::list<int, std::allocator<int> > >]’
sna_afra.cpp:62: instantiated from here
/usr/include/c++/4.3/bits/stl_vector.h:932: error: no matching function for call to ‘std::vector<std::list<int, std::allocator<int> >, std::allocator<std::list<int, std::allocator<int> > > >::_M_fill_initialize(size_t, int&)’
/usr/include/c++/4.3/bits/stl_vector.h:974: note: candidates are: void std::vector<_Tp, _Alloc>::_M_fill_initialize(size_t, const _Tp&) [with _Tp = std::list<int, std::allocator<int> >, _Alloc = std::allocator<std::list<int, std::allocator<int> > >]
[code]was mich leider völlig überfordert. kann mir jemand helfen?
unter windows hab ich die fehlermeldung auch nicht.viele grüße
amton
-
Zeig mal konkreten Code. Vor allem, was rawdata ist.
-
hallo drakon,
hier ist das entsprechende restprogramm:
#include<vector> #include<list> using namespace std; vector<vector<list<int> > > adjacency; int main(int argc, char *argv[]) { adjacency.assign(300,vector<list<int> >(20,0)); }an der fehlermeldung ändert sich nichts:
/usr/include/c++/4.3/bits/stl_vector.h: In member function ‘void std::vector<_Tp, _Alloc>::_M_initialize_dispatch(_Integer, _Integer, std::__true_type) [with _Integer = int, _Tp = std::list<int, std::allocator<int> >, _Alloc = std::allocator<std::list<int, std::allocator<int> >>]’: /usr/include/c++/4.3/bits/stl_vector.h:290: instantiated from ‘std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const _Alloc&) [with _InputIterator = int, _Tp = std::list<int, std::allocator<int> >, _Alloc = std::allocator<std::list<int, std::allocator<int> > >]’ vectorerror.cpp:10: instantiated from here /usr/include/c++/4.3/bits/stl_vector.h:932: error: no matching function for call to ‘std::vector<std::list<int, std::allocator<int> >, std::allocator<std::list<int, std::allocator<int> > > >::_M_fill_initialize(size_t, int&)’ /usr/include/c++/4.3/bits/stl_vector.h:974: note: candidates are: void std::vector<_Tp, _Alloc>::_M_fill_initialize(size_t, const _Tp&) [with _Tp = std::list<int, std::allocator<int> >,_Alloc = std::allocator<std::list<int, std::allocator<int> > >]danke für deine hilfe!
Anton
-
Es muss ja auch heißen
adjacency.assign(300,list<int>(20,0));immerhin willst du einen vector mit list-Instanzen füllen.
[edit]Sorry, Hab mich verlesen. Siehe campers Post.
also soadjacency.assign(300,vector<list<int> >(20));[edit]
-
vector<list<int> >(20,0)Was soll der zweite Parameter 0 bewirken? Wenn ich das richtig sehe, rufst du so den Iterator-Konstruktor von vector auf; und einfache Integer sind natürlich keine Iteratoren.
-
hallo,
vielen dank, jetzt klappt es. wahrscheinlich war die alte compiler version einfach nicht so streng ;).
anton