Vector attribute of a class containing vector attributes

Hi,
I've got a problem with a class Player that should have a vector of Monster as an attribute. The real problem is that the class Monster has already a vector of Attack as attribute, so the compiler says:

||=== Build: Debug in exercise (compiler: GNU GCC Compiler) ===|

c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_construct.h||In instantiation of 'void std::_Construct(_T1*, _Args&& ...) [with _T1 = Mostro; _Args = {const Mostro&}]':|

c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_uninitialized.h|77|required from 'static _ForwardIterator std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const Mostro*, std::vector<Mostro> >; _ForwardIterator = Mostro*; bool _TrivialValueTypes = false]'|

c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_uninitialized.h|119|required from '_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const Mostro*, std::vector<Mostro> >; _ForwardIterator = Mostro*]'|

c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_uninitialized.h|260|required from '_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = __gnu_cxx::__normal_iterator<const Mostro*, std::vector<Mostro> >; _ForwardIterator = Mostro*; _Tp = Mostro]'|

c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_vector.h|310|required from 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = Mostro; _Alloc = std::allocator<Mostro>; std::vector<_Tp, _Alloc> = std::vector<Mostro>]'|

C:\exercise\giocatore2.cpp|14|required from here|

c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_construct.h|77|error: no matching function for call to 'Mostro::Mostro(const Mostro&)'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_construct.h|77|note: candidates are:|

C:\exercise\mostro2.h|13|note: Mostro::Mostro(int, std::string, int, int, int, int, std::vector<Attacco>&)|

C:\exercise\mostro2.h|13|note: candidate expects 7 arguments, 1 provided|

C:\exercise\mostro2.h|12|note: Mostro::Mostro(Mostro&)|

C:\exercise\mostro2.h|12|note: no known conversion for argument 1 from 'const Mostro' to 'Mostro&'|

||=== Build failed: 1 error(s), 6 warning(s) (0 minute(s), 1 second(s)) ===|


I think the principal error is "no matching function for call to 'Mostro::Mostro(const Mostro&)'"

//in giocatore2.h :
Giocatore (std::string nome, std::vector <Mostro> squadra);

//in mostro2.h :
Mostro (int ID, std::string specie, int PS, int PA, int PD, int PV, std::vector <Attacco> v);


Mostro=monster, giocatore=player, squadra=team
Last edited on
error: no matching function for call to 'Mostro::Mostro(const Mostro&)'
|note: candidates are:
Mostro::Mostro(Mostro&)
-¿did you need to code the copy constructor? (¿why is member-wise copy not good for you?)
-¿do you have a good reason to not ask for a constant reference? (¿how are you changing the parameter, and why?)
Thanks for the hints ne555! But I've found the errors and resolved! I needed to code the copy constructor but I didn't know that it's indispensable the use of constant getters...thank you however!
Last edited on
Topic archived. No new replies allowed.