-4

The code is

Vect::~Vect()
/*
PRE:  None
POST: free pVect
*/
{
    cout << "(__||  - DELETE (unlock the memory for): " << (*this) << endl;
    // Put code below ....


}

Basically, I need it to correctly free pVect so that my other fuctions can work.

Also there is a .h file with this double* pVect;

  • 1
    Welcome to Stack Overflow. Please read [the help pages](http://stackoverflow.com/help), take the SO [tour], read [ask], as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Lastly please learn how to [edit] your questions to improve them (like removing totally unrelated tags, like the C language tag). – Some programmer dude Nov 21 '21 at 17:50
  • We can't possibly help given only the information in the question. – drescherjm Nov 21 '21 at 18:09
  • I'll post another question in 2 hours with all the information – ElGenericoIsABigBoy Nov 21 '21 at 18:16
  • 1
    No don't post the same question again, instead **[edit]** your current question to add information. – Some programmer dude Nov 21 '21 at 18:18
  • Alright I just edited it :D – ElGenericoIsABigBoy Nov 21 '21 at 18:27
  • After you add a destructor you may get into a problem of double deletes. You probably want to read about this: [https://stackoverflow.com/questions/4172722/what-is-the-rule-of-three](https://stackoverflow.com/questions/4172722/what-is-the-rule-of-three) – drescherjm Nov 21 '21 at 18:57

1 Answers1

0

It would have been nice if you'd provided a full but minimally-producable example to start with. Let's try this:

class Vect {
public:
    ~ Vect();
private:
    double *pVect = nullptr;
};

Vect::~ Vect() {
    delete [] pVect;
}

Make sure you keep pVect equal to a nullptr unless it contains a valid address. Which means you absolutely should give it a default value like I did.

Joseph Larson
  • 8,530
  • 1
  • 19
  • 36