Unable to push_back to vector

PapaSmurf

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

azhamn

.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.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Insert or push_back to end of a std::vector?

From Dev

Cost of std::vector::push_back either succeeding or having no effect?

From Dev

string Vector push_back failing in class

From Dev

Calling std::vector::push_back() is changing previous elements in vector?

From Dev

vector::push_back and std::move

From Dev

Thread safety std::vector push_back and reserve

From Dev

Implementatnion of std::vector::push_back in MSVC

From Dev

How to use vector iterators when using vector<>::push_back()

From Dev

C++ Vector: push_back Objects vs push_back Pointers performance

From Dev

vector push_back zero into an empty vector

From Dev

garbage values for vector push_back

From Dev

Why are there two overloads for vector::push_back?

From Dev

Vector and push_back() behavior

From Dev

push_back new element to vector

From Dev

vector push_back in STL?

From Dev

Calling std::vector::push_back() is changing previous elements in vector?

From Dev

vector push_back causes assertion error but list push_back works

From Dev

c++ vector - what's the difference between push_back(*new obj()) and push_back(obj())?

From Dev

Implementatnion of std::vector::push_back in MSVC

From Dev

How to use vector iterators when using vector<>::push_back()

From Dev

garbage values for vector push_back

From Dev

Vector push_back incredibly slow

From Dev

push_back a vector of vectors into a vector

From Dev

Vector push_back Array of doubles

From Dev

Push_back variadic function parameters into a vector?

From Dev

c++ push_back() a struct into a vector

From Dev

vector of reference wrapper, push_back failure?

From Dev

unable to push back a pointer into vector

From Dev

push_back a pointer to a vector of pointers

Related Related

HotTag

Archive