And for 17 I added vector<T*> del; to the private section
Why did you add another vector? Why didn't you just use the vector that is already in the class?
Would you please explain the exercises for me what they really want?
What does the code to exercise 15 look like? Does the code for Exercise 15 compile and produce the desired results? Exercise 16 is based on the code for Exercise 15.
Exercise 16 is probably trying to illustrate the differences between pointers and references in the content of the "enhanced" vector class.
and the one for 17 looks very awkward to me.
What, exactly, looks awkward to you? You need to iterate through the vector and delete the memory, which your loop accomplishes.
When dealing with templates you should post a small complete program that illustrates the problems you are encountering. You need to show how you're using that template class.
I've defined the operator * in line 33 and use it like:
1 2 3 4 5 6 7 8 9 10 11 12 13
int main() {
pvector<double> v1;
for (size_t i = 0; i < 10; i++)
v1.push_back(newdouble(2.5*i));
cout << "vector<double> v1 = ";
for (constauto& v : v1)
cout << *v << ' ';
cout << endl;
*v1(0) = 3;
return 0;
}
It shows these errors for line 11:
Severity Code Description Project File Line Suppression State
Error (active) E0980 call of an object of a class type without appropriate operator() or conversion functions to pointer-to-function type
Severity Code Description Project File Line Suppression State
Error C2064 term does not evaluate to a function taking 1 arguments
Why did you add another vector? Why didn't you just use the vector that is already in the class?
It says "which objects are deleted by the destructor". And destructors don't accept arguments to, for example, tell them which object to delete. So I thought of a vector the user puts whatever object they want to delete into that and in the destructor to delete that vector.
What does the code to exercise 15 look like? Does the code for Exercise 15 compile and produce the desired results? Exercise 16 is based on the code for Exercise 15.
The code for 16 minus the operator * is the code for 15 and I used as above in main() and works fine.
What, exactly, looks awkward to you?
I meant defining another vector (del) to be able to tell the destructor which object to be deleted.
It says "which objects are deleted by the destructor". And destructors don't accept arguments to, for example, tell them which object to delete. So I thought of a vector the user puts whatever object they want to delete into that and in the destructor to delete that vector.
Did you still have the other vector in the class? If so did you delete the elements of that vector as well?
For your error messages shouldn't main() be more like:
Let's solve the exercise 16 first.
This is the code I test for this point of the code. I get those errors for line 54 where I want to use the overloaded operator* there.
I get those errors for line 54 where I want to use the overloaded operator* there.
To use the overloaded operator * as you have defined it you would need to do the following v1 * 0 = 3; since you have overloaded the multiplication(Binary) operator not a "pointer"(unary) operation.