I have created an instance of the class however I am unable to push_back the name of the ship to the vector.
if (rows->_rows.size() != rows->rows_Size) { rows->_rows.push_back (ship->name); }
I get the following errors.
Error 1 error C2664: 'void std::vector<_Ty>::push_back(Berths &&)' : cannot convert parameter 1 from 'std::string' to 'Berths &&'
6 IntelliSense: no instance of overloaded function "std::vector<_Ty, _Alloc>::push_back [with _Ty=Berths, _Alloc=std::allocator]" matches the argument list argument types are: (std::string) object type is: std::vector>
The code for the class I am trying to add the data to is:
#pragma once class Berths; #include "Berths.h" #include "Ship.h" #include <iostream> #include <vector> class Rows { public: Rows(void); ~Rows(void); std::vector<Berths> _rows; int rows_Size; bool dock(Ship ship); bool undock(Ship ship); };
Rows::Rows(void)
{
rows_Size = 10;
}
Any ideas as to what is causing this?
Thanks
.size()
is a member function of a vector. Hence you should use rows->_rows.size()
instead. It's a common mistake we all make.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments