Method called on freed object

From RAD Studio
Jump to: navigation, search

Go Up to Access Errors


The Method Called On Freed Object error is similar to the Access In Freed Memory error, but is caused by a call to a method in a freed object rather than accessing memory, as such.

#pragma hdrstop
#include <tchar.h>
#pragma argsused
#include<stdio.h>
#include<dir.h>
class someclass{
	int fnumber;
  public:
	int getnumber(){return fnumber;}
	void setnumber(int nw){fnumber = nw;}
	int doublev(int val){return val*2;}
	int publicalval;

};

void myf()
{
  someclass *myc = new someclass();
  delete myc;
  myc->doublev(5); // error
}


int _tmain(int argc, _TCHAR* argv[])
{
	myf();
	return 0;
}