Destructor causes error upon delete double array

Pages: 123
I certainly would recommend to use vectors over arrays. You have have seen how error prone it is to work with pointers and dynamic arrays. There is no performance difference between arrays and vectors. Vectors internally use arrays but handle the memory for you.

There is no real difference between classes and structs. Only difference is that in classes everything is private by default, in structs everything is public by default.

You are welcome :)

As Thomas said, std::vector is very useful and very flexible. Mastering std::vector is the key to your success!

Until next time,
! :)
i have one last question that just came up...
i tried to implement the code now in the original project.
the exact same function
1
2
3
4
5
6
7
	// assignment constructor for &v
	VEC& operator = (const VEC &v) {
		if (data) delete[] data;
		dim = v.dim;
		data = new double[dim];
		memcpy(data, v.data, sizeof(double) * dim);
	}


that works for the side-project, also the rest of the class is nearly the same. (only some more parameters that arent involved here)

but now i get this error:
 
'VEC::operator=': must return a value


what does it mean, it must return a value? I mean, what should it even return? since exact same function works fine on side-project...
VEC& operator = (const VEC &v)
It is Thomas1975's.

If the compilier demands a return value, you must supply it in the function body. Very often, the return value is just itself - return (*this);

void return value is fine too, but later you will definitely learn to choose the most approriate return value for each your operator functions. No worries there :)
thanks! I love you and your patience! <3
/closed
Topic archived. No new replies allowed.
Pages: 123