Mam "problem" z zaimplementowaniem w C++ tego, co Java używa od razu. Mianowicie chodzi mi o referencję. Jak wiadomo, w Javie wszystko jest referencją (tak upraszczając;))
Ja mam pewną klasę - User. w programie głównym chcę utworzyć wektor zawierający referencje do obiektów klasy User. Nie ma w tym nic dziwnego - to samo bym osiągnął pisząc to w Javie, z użyciem listy i swojej klasy. (Czy na pewno?) Czy wektor referencji: vector<User&> w; to to samo co lita w Javie z obiektami klasy User?
A jakbym użył czegoś takiego: vector<User> &w; to byłoby to dobre rozwiązanie? Czy niekoniecznie? Podkreślam, że zależy mi na osiągnięciu funkcjonalności takiej, jaką ma Java. (A w Javie nie mogę tego napisać; MUSZĘ w Cpp;))
Proszę o pomoc.Deklaracja czegoś takiego: vector<User&> w; daje mi takie błędy:
/usr/include/c++/4.6/bits/allocator.h:92|11|instantiated from ‘std::allocator<User&>’|
/usr/include/c++/4.6/bits/stl_vector.h:73|60|instantiated from ‘std::_Vector_base<User&, std::allocator<User&> >’|
/usr/include/c++/4.6/bits/stl_vector.h:180|11|instantiated from ‘std::vector<User&>’|
/home/ja/tester.cpp:17|19|instantiated from here|
/usr/include/c++/4.6/ext/new_allocator.h|59|error: forming pointer to reference type ‘User&’|
/usr/include/c++/4.6/ext/new_allocator.h|60|error: forming pointer to reference type ‘User&’|
/usr/include/c++/4.6/bits/stl_vector.h:73|60|instantiated from ‘std::_Vector_base<User&, std::allocator<User&> >’|
/usr/include/c++/4.6/bits/stl_vector.h:180|11|instantiated from ‘std::vector<User&>’|
/home/ja/tester.cpp:17|19|instantiated from here|
/usr/include/c++/4.6/bits/allocator.h|97|error: forming pointer to reference type ‘User&’|
/usr/include/c++/4.6/bits/allocator.h|98|error: forming pointer to reference type ‘User&’|
/home/ja/tester.cpp:17|19|instantiated from here|
/usr/include/c++/4.6/bits/stl_vector.h|206|error: no members matching ‘std::vector<User&>::_Base {aka std::_Vector_base<User&, std::allocator<User&> >}::_M_allocate’ in ‘std::vector<User&>::_Base {aka struct std::_Vector_base<User&, std::allocator<User&> >}’|
/usr/include/c++/4.6/bits/stl_vector.h|207|error: no members matching ‘std::vector<User&>::_Base {aka std::_Vector_base<User&, std::allocator<User&> >}::_M_deallocate’ in ‘std::vector<User&>::_Base {aka struct std::_Vector_base<User&, std::allocator<User&> >}’|
/home/ja/tester.cpp||In function ‘int main()’:|
/home/ja/tester.cpp|18|error: ‘uzytk’ was not declared in this scope|
/home/ja/tester.cpp|21|warning: comparison between signed and unsigned integer expressions [-Wsign-compare]|
/usr/include/c++/4.6/bits/stl_vector.h||In destructor ‘std::vector<_Tp, _Alloc>::vector() [with _Tp = User&, _Alloc = std::allocator<User&>]’:|_Vector_base() [with _Tp = User&, _Alloc = std::allocator<User&>]’:|
/home/ja/tester.cpp:17|19|instantiated from here|
/usr/include/c++/4.6/bits/stl_vector.h|350|error: ‘struct std::_Vector_base<User&, std::allocator<User&> >::_Vector_impl’ has no member named ‘_M_start’|
/usr/include/c++/4.6/bits/stl_vector.h|350|error: ‘struct std::_Vector_base<User&, std::allocator<User&> >::_Vector_impl’ has no member named ‘_M_finish’|
/usr/include/c++/4.6/bits/stl_vector.h||In member function ‘std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = User&, _Alloc = std::allocator<User&>, std::vector<_Tp, _Alloc>::size_type = unsigned int]’:|
/home/ja/tester.cpp:21|32|instantiated from here|
/usr/include/c++/4.6/bits/stl_vector.h|571|error: ‘const struct std::_Vector_base<User&, std::allocator<User&> >::_Vector_impl’ has no member named ‘_M_start’|
/usr/include/c++/4.6/bits/stl_vector.h|571|error: ‘const struct std::_Vector_base<User&, std::allocator<User&> >::_Vector_impl’ has no member named ‘_M_finish’|
/usr/include/c++/4.6/bits/stl_vector.h||In destructor ‘std::_Vector_base<_Tp, _Alloc>::
/usr/include/c++/4.6/bits/stl_vector.h:218|15|instantiated from ‘std::vector<_Tp, _Alloc>::vector() [with _Tp = User&, _Alloc = std::allocator<User&>]’|
/home/ja/tester.cpp:17|19|instantiated from here|
/usr/include/c++/4.6/bits/stl_vector.h|142|error: ‘struct std::_Vector_base<User&, std::allocator<User&> >::_Vector_impl’ has no member named ‘_M_start’|
/usr/include/c++/4.6/bits/stl_vector.h|142|error: ‘struct std::_Vector_base<User&, std::allocator<User&> >::_Vector_impl’ has no member named ‘_M_start’|
/usr/include/c++/4.6/bits/stl_vector.h|142|error: ‘struct std::_Vector_base<User&, std::allocator<User&> >::_Vector_impl’ has no member named ‘_M_end_of_storage’|
/usr/include/c++/4.6/bits/stl_vector.h|142|error: ‘_M_deallocate’ was not declared in this scope|
/usr/include/c++/4.6/bits/stl_vector.h||In constructor ‘std::_Vector_base<_Tp, _Alloc>::_Vector_impl() [with _Tp = User&, _Alloc = std::allocator<User&>]’:|
/usr/include/c++/4.6/bits/stl_vector.h:107|17|instantiated from ‘std::_Vector_base<_Tp, _Alloc>::_Vector_base() [with _Tp = User&, _Alloc = std::allocator<User&>]’|
/usr/include/c++/4.6/bits/stl_vector.h:218|15|instantiated from ‘std::vector<_Tp, _Alloc>::vector() [with _Tp = User&, _Alloc = std::allocator<User&>]’|
/home/ja/tester.cpp:17|19|instantiated from here|
/usr/include/c++/4.6/bits/stl_vector.h|83|error: using invalid field ‘std::_Vector_base<_Tp, _Alloc>::_M_start’|
/usr/include/c++/4.6/bits/stl_vector.h|83|error: using invalid field ‘std::_Vector_base<_Tp, _Alloc>::_M_finish’|
/usr/include/c++/4.6/bits/stl_vector.h|83|error: using invalid field ‘std::_Vector_base<_Tp, _Alloc>::_M_end_of_storage’|
||=== Build finished: 18 errors, 1 warnings ===|