Блог пользователя CLICKHERE

Автор CLICKHERE, история, 4 года назад, По-английски
#include <bits/stdc++.h>
using namespace std;

class a{
public:
	vector<int> arr(5);
};

int main() {
 a b;
}

why it is giving error at vector<int> arr(5);

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

»
4 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

It's not allowed. you can use vector <int> arr = vector<int> (5);

  • »
    »
    4 года назад, # ^ |
    Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

    Okay but why? how to declare this in class vector<vector<pair<T, pair<T, T2>>>> adjList(5) ?

    vector<vector<pair<T, pair<T, T2>>>> adjList = vector<vector<pair<T, pair<T, T2>>>> (5) like this?

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      you can use auto type

      vector<vector<pair<T, pair<T, T2>>>> adjList = vector<vector<pair<T, pair<T, T2>>>> (5)

      this code is equal to fist code:

      auto adjList = vector<vector<pair<T, pair<T, T2>>>> (5)

»
4 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Vector size is set in the constructor function.

»
4 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

if you are declaring a class of 'a' then to declare a vector, you should follow this syntax

class fun { vector *v; public: fun() { v = new vector [5]; } };

this syntax is correct...i have used it so many times.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

thanks in advance for writing this blog! I have had the same problem for a long time :)