the C++ have something similar to __event(VS.NET) or afx_msg(VC++)?
for i do something like these:
Code:class events { public: afx_msg void OnDestroy(); }; events test; void test::OnDestroy() { MessageBox(NULL, "hi", "hello", MB_OK); }
the C++ have something similar to __event(VS.NET) or afx_msg(VC++)?
for i do something like these:
Code:class events { public: afx_msg void OnDestroy(); }; events test; void test::OnDestroy() { MessageBox(NULL, "hi", "hello", MB_OK); }
i'm so sorry, but i'm confused on your thot
i can't 'connect' my sample code with your template function
Here's another example of on how to use callbacks for notifications or events.
Code:// Assume this is a window class that represents a visible window on the screen class Window { public: // When we create the window, we can tell it to tell us when something happens, e.g. it is being destroyed. template<typename F> Window(F OnDestroy) { // ...Do stuff... // We store the function we're supposed to call when the destroy notification fires. m_OnDestroy = OnDestroy; } ~Window() { // We're being destroyed, so call the function the caller specified to notify them when we're being destroyed. m_OnDestroy(); } private: // Used to store the function to call for the On Destroy notification. We use std::function to erase the signature type so we don't have to template the class itself. std::function<void()> m_OnDestroy; }; // Assume this is where your code that uses Window is. class MyClass { public: // Assume this function is currently being executed void SomeFunction() { // Create a new window, and tell it to notify us when it's being destroyed. We pass a lambda, which calls our OnDestroy function. Window MyWindow([this] { OnDestroy(); }); // ...Do stuff... // Window goes out of scope here and thus invokes our OnDestroy function. } void OnDestroy() { std::cout << "MyWindow is being destroyed...\n"; } }
theres 2 things on MyClass:
1 - it's a class, instead an object;
2 - again... we redefinition the OnDestroy on MyClass(if we need use it outside of class).
(i'm sorry if i fail on keywords)
please see again my sample:
is there another keyword, instead 'afx_msg', for i don't need redifinition the 'OnDestroy' on 'test' object?Code:class events { public: afx_msg void OnDestroy(); }; events test; void test::OnDestroy()//error: the OnDestroy was not declared on test { MessageBox(NULL, "hi", "hello", MB_OK); }
(i'm sorry, but i'm trying do instances that let change some functions, on Global Scope)
If you are switching from NET to the pure WinAPI you will find numerous differences. WinAPI documentation: Learn to Program for Windows in C++
i'm learning more and more about C\C++ and Win32. but i had notice several things that are relay practical and useful on programming.
that's why, with some help, i had created the property class and it's excelent... well except for some C++ professionals(some things i will not understand, but maybe are rules.. i don't know).
maybe, with time, i will figure out the solution. thanks to all
I think we have no idea what you are asking about.
If you are asking about class methods instead of object methods; see the static keyword.
FYI: The "::" scope symbol normally should have a class name or a namespace name in front of it.
That is what caused the error.
Tim S.
"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson