#include ...">

Why does he say that "push_back" has not been declared?

Why does he say that "push_back" has not been declared?

#include <iostream>
#include <vector>
using namespace std;
int main()
{
  vector <int> v(30);
  v[0].push_back(0);
 return 0;
}
+3
source share
6 answers

v[0]is a reference to the source element in vector; it is not himself vector. An element has a type intthat is not an object of the class type and therefore has no member functions.

Are you looking for v.push_back(0);?

Notice what vector<int> v(30);creates vectorwith 30 elements in it, each with a value of zero. The call v.push_back(0);will increase the size vectorto 31. This may or may not be the behavior you want; if this is not the case, you need to clarify what exactly you are trying to do.

+14
source

v.push_back(0), push_back - , .

+2

:

#include <iostream>
#include <vector>
using namespace std;
int main()
{
  vector <int> v(30);
  v.push_back(0);
  return 0;
}

, v [0] - , int. v.

+2

v.push_back(0); _back . .

+2

v.push_back(0), v[0] int, a vector.

+2

.

v . v[0] , , ( int).

v[0] push_back.
(v).

+2

Source: https://habr.com/ru/post/1788913/


All Articles