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

Автор CLICKHERE, история, 7 лет назад, По-английски
#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
  • Проголосовать: не нравится

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

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

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

Vector size is set in the constructor function.

»
7 лет назад, скрыть # |
← 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.

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

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