| harsha (8) | |
|
When i compile this prog, i get errors sayin 1.'d' undeclared" 2.Each undeclared identifier is reported only once for each function it appears in. what is the problem here with declaration of an array of vectors?? #include<iostream> #include<vector> using namespace std; int main() { int m,a,b,i; cin>>m; for(i=0;i<m;i++) { vector<int> d[i]; } for(i=0;i<m;i++) { cin>>a>>b; d[a].push_back(b); } return 0; } | |
|
|
|
| Zhuge (2974) | |
| You declare d inside one of the for loops; it doesn't exist outside that for loop so an attempt to access it in the next one generates the error. | |
|
|
|
| Felicia123 (176) | |||
example
DO you know clearly about vector? | |||
|
|
|||
| harsha (8) | |
| @felicia123 yeah im fine with what u've coded but my prob is wit assigning an array of vectors in a better scope | |
|
|
|
| harsha (8) | |
| @zhuge yep i've got it.. but for declaring an array of vectors,, i need a loop.. so how do i define it in a better scope,, i.e how do i define it such tat it can be accessed throughout the main() function?? | |
|
|
|
| Felicia123 (176) | |
|
like that why you want to use vector? quite confuse with yours question. haha.. | |
|
|
|
| cire (2362) | |||
|
There are two problems with the original code. d only exists within the scope of the first for statement, and one may not define an array with a variable that is not also a compile-time constant: i, although some compilers have an extension enabled by default that allows it. Since you're already using a vector, why not just use a vector of vectors?
| |||
|
Last edited on
|
|||