- #71
yungman
- 5,755
- 293
I know what you are talking all along. I cannot make it work because the code vector<int>numSold(defaultNSold) cannot work in all situation, maybe that's answer to my question already, I cannot use this to copy vector in the function where I have to define the vector in the function parameters.Jarvis323 said:You can't make it work because it doesn't make any sense. If you want a new variable, then just use a different name. It won't be the same variable of course. It doesn't make a difference whether it's inside a function or not, you can't use the same name for two different variables. If it worked for you outside a function, then that's not what you did. Here are some examples.
C:// this is wrong vector< int > x; vector< int > & y = x; vector< int > y( d ); // the name y is already used // this is also wrong vector< int > x; vector< int > x; // the name x is already used // this is also wrong vector< int > x; vector< int > x( d ); // the name x is already used // this is also wrong vector< int > x; vector< int > x = d;// the name x is already used // this is correct vector< int > x = d; // this is correct and exactly equivalent to the last version vector< int > x (d); // this is correct as well vector< int > x; x = d;
And it's not because it's a vector either.
C:// this is wrong int x; int & y = x; int y( d ); // the name y is already used // this is also wrong int x; int x; // the name x is already used // this is also wrong int x; int x( d ); // the name x is already used // this is also wrong int x; int x = d;// the name x is already used // this is correct int x = d; // this is correct int x (d); // this is correct as well int x; x = d;