- Joined
- Nov 17, 2003
- Location
- Michigan, USA
I want a macro or a template function that will determine if a class has a vft. Ultimatly, I want something that will reset all the fields of a class to 0 except the vft.
Something similiar to doing this in C:
memset(&obj, 0, sizeof(obj));
This works on any struct or class as long as it doesn't have virtual functions. When it does have virtual functions, the vft pointer gets reset to NULL and the virtual functions no longer work. I'd like something like this:
Its the has_vft<T> function I don't know how to write.
Something similiar to doing this in C:
memset(&obj, 0, sizeof(obj));
This works on any struct or class as long as it doesn't have virtual functions. When it does have virtual functions, the vft pointer gets reset to NULL and the virtual functions no longer work. I'd like something like this:
Code:
void classset<T>(T* obj){
if (has_vft<T>()){
memset((char*)(obj) + sizeof(void*), 0, sizeof(T) - sizeof(void*));
} else {
memset(&obj, 0, sizeof(T));
}
}
Its the has_vft<T> function I don't know how to write.