So here is what I'm trying to do:

Inline Code Example Here
my constructor takes a char pointer:

lengthString = strlen(nameSentFromMain) + 1;
namePrivate = new char[lengthString];
strcpy_s(namePrivate,lengthString,nameSentFromMain);

next in the destructor to avoid memory leaks I have:

delete [] namePrivate;

The error I'm gettting says _BLOCK_TYPE_IS_VALID(pHead->nBlockUse). Strangely enough the destructor seems to be getting called twice for each new. Has anyone run into this before? I couldn't get a solid answer from google.

Have you defined a copy-constructor? One that performs a deep-copy? You need to obey the rule of three when you write a class that holds a resource. You can also read this tutorial.

The double-destruction comes from the fact the your object must be getting copied, and when copied, it only copies the pointer, not the data it points to, and thus, you have two objects holding the same pointer, and when the second object is destroyed in calls delete a second time on the same pointer.

If you want to save yourself the trouble, just use the standard std::string class instead of a C-style string (char pointer).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.