Question: C++: double& Vector::operator[](int i) { if (i <0 || size()

C++:

double& Vector::operator[](int i)

{

if (i<0 || size()<=i)

throw out_of_range("Vector::operator[]");

return elem[i];

}

1.What is the purpose of the parameter i to the method? If you were to write the documentation for the function, what description would you include to teach people unfamiliar with the library how to use this function? In addition to this English description, write a small main() program that creates a vector and demonstrates the correct usage of operator[ ]. Note: the authors vector class is capital Vector, and does not yet support templates. C++

2. Notice the methods return value is double& and not double. Why? Provide an English explanation of what this additional & enables us to do, and write a small main() program that demonstrates in code the an example of that reasoning being applied.C++

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!