Since i need to define its size in runtime, i need a vector. I tried the following but i get a compiling error: "error: ‘V’ is not a type"
#include<iostream>
#include<vector>
class graph {
private:
int V;
std::vector<int> row(V);
std::vector<std::vector<int>> matrix(V,row);
public:
graph(int v): V(v) {}
};
Is there something i am failing to understand? is it even allowed to initialize a vector this way?
>Solution :
The compiler considers these lines
std::vector<int> row(V);
std::vector<std::vector<int>> matrix(V,row);
as member function declarations with parameters with omitted type specifiers.
It seems what you need is the following
class graph {
private:
int V;
std::vector<std::vector<int>> matrix;
public:
graph(int v): V(v), matrix( v, std::vector<int>( v ) ) {}
};