How to call the original function when it's overridden?
MFC has a class named CWinApp, and CWinApp has a destruction
function called ~CWinApp(). Now I want to override ~CWinApp() yet still want to call the original version of ~CWinApp(), the code is as follows: Code:
void wrap(void) |
|
Quote:
His question was related to two different classes, while mine is associated with the same class. What I concerns about is how to get the address of the function before it's overridden, and if one function is overridden, does its original version still exist? |
sorry i am not programmer just trying to help
|
When overriding classes the constructor is called automatically in the constructor of the inheriting class (before the constructor of the inheriting class). Same with the deconstructor.
To call the base function explicitely use the syntax Base::Function, you should never call deconstructors explicitely though. Use delete of your class is an object allocated with new. |
@BlackWhite:
What you only need to know is class method It's standard in all object programming... +1 / mr.exodia : not a good idea to call destructor ! |
Quote:
that ~MyClass() will be automatically called when the MyClass object is deleted, then I can decide whether to transfer control to ~CWin() in ~MyClass(). But the weird situation is that ~CWin() is called instead of ~MyClass() when the MyClass object is deleted. So, how to deal with it? |
you should never call a destructor explicitly! pull the destructor code into another method, if you think you do.
in the case of 'class MyClass : public CWin' both ~MyCLass() and ~CWin() destructor will be invoked by the compiler (~MyCLass first). There is nothing you can do about it, you cant decide. |
@BlackWhite: here is an example of how you should work. When you want to call the deconstructor, let the variable go out of scope or delete it.
Code: http://codepad.org/1jq6nsQF Output: Code:
test() called! |
Quote:
Quote:
Quote:
cfr. http://stackoverflow.com/questions/461203/when-to-use-virtual-destructors Hope this helps a bit :) Regards, Tony |
Quote:
instead, it is deleted by the system. In fact, I wrote an MFC DLL, the object is "theApp". Here is the code: Code:
#include "stdafx.h" function install_F12_hook() to install a keyboard hook, HELLO.EXE runs happily and closes normally, but there are problems with other running processes which are also hooked by "hook.dll". When I close some other process, that process will crash. I traced the crash by OllyDBG, and found that ~CWinApp() is the bad guy. Code:
*1402107 DllEntryPoint |
All times are GMT +8. The time now is 11:15. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX