Hi, I have come across the following code while trying to understand a program:
vector<double> P(ny*ny, 0.0);
Based on what I have read in a tutorial, the first component in the parentheses should be the first element in the vector, and the second component should be the last element in the vector. In this case the second component is 0.0, which is strange to me, because previously ny was assigned a value of 21. Please help. Thank you very much.
I am afraid you misunderstood or the tutorial is rubbish. The first element in the parentheses is the number of elemenst and second is the value for all elements.
OP: are you sure the parentheses were rounded and not curly?
Using the constructor (parentheses) creates a vector with ny * ny (25) elements with all the elements initialized to zero. Using aggregate_initialization {} produces a vector with two elements with values of 25.0 and 0.0.
Using the constructor (parentheses) creates a vector with ny * ny (25) elements with all the elements initialized to zero. Using aggregate_initialization {} produces a vector with two elements with values of 25.0 and 0.0.
Thanks for the information. It's amazing how people who came up with these languages were able to put in so many detailed rules.