Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

CLICKHERE's blog

By CLICKHERE, history, 4 years ago, In English
#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);

  • Vote: I like it
  • +2
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    4 years ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    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 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Vector size is set in the constructor function.

»
4 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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