Click here to Skip to main content
15,894,720 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
class sortedVector
{
	
public:
	int* vect;
	int length;
	int size;

	sortedVector(int n):size(n)
	    { 
              length=0;
              vect=new int[n];         
            }
	~sortedVector()
	    {delete [] vect; }
//methods....
};
void main()
{
sortedVector v(5);
//....
v.~sortedVector(); //if I write this, I get a run-time error ASSERTION_FAIL

}


The program runs ok, not this is the problem. As I said, if I call the destructor, I get that run-time error, if I don't call it everything is OK. My question is: IS THE MEMORY DEALOCATED if I don't call the destructor explicitly? because I want to avoid memory leaks.
Thanks in advance!
Posted

1 solution

You must not call the destructor as function. The destructor and constructor are functions they are called on delete or new or implicit on leaving or entering the declaration scope (stack).
In your case your destructor is called twice.
If you free your allocated memory in destructor - everything is ok.
Regards.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Aug-11 14:16pm    
Correct, a 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900