Class deconstructors?

Dec 24, 2008 at 2:03am
I have here a bit of code like this:
1
2
3
4
5
6
void *data;
lol_e type;
public:
lol_t() {data = (void*)new int(0); type = numbar;}
lol_t(NUMBAR n) {data = (void*)new int(n); type = numbar;}
~lol_t() { delete (void*)data; }


inside the lol_t class. Now everything compiles, but I get an error that says that "deleting void* is undefined"
Did I set up the deconstructor properly?
And to call it I would use delete (lol_t variable name here) right?
Dec 24, 2008 at 2:28am
It's what the error says. You can't delete a pointer to void because void has no size. How many bytes is the compiler supposed to free? 1? 2? 4?
You need to cast the pointer to something before you can delete it. Since you created it as an int, you should cast to int *.

What is lol_t::lol_t(NUMBAR) supposed to do?
Dec 24, 2008 at 2:32am
(Whoops, I noticed that that "public:" shouldn't exist)

I typedef'd NUMBAR to mean int...

Thank you, changing delete (void*)data to delete (int*)data fixed the errors...
Topic archived. No new replies allowed.