I am currently working on a custom "String" class in C++ for a project.
When I just use ONE String, it works fine. However, when I try to create an array (using std::vector) of them, the following error occurs: _BLOCK_TYPE_IS_VALID(pHead->nBlockuse)
As I understand it, this means that I somehow freed memory twice. If this is correct, I really can't find the location.
From what I can tell, when I use return String(...), it creates a new String object, returns a copy of it and then calls the destructor as it goes out of scope. Is this correct? If so, is this the problem?
The String object will have to be copied when it's returned from the function so you have to implement the copy constructor and the copy assignment operator to handle copying correctly.
a, b and c all have str members pointing to the same piece of memory, so when their respective destructors are called the same memory will be freed 3 times.
the vector will copy the string which you push,that is it will call the default copy constructor,String::String,so you should implement the default copy constructor
double delete,one is you delete and the other is vector delete