I searched for answers to this but can not find enough detail. Be patient, I'm a beginner using Visual C++. I have created a desktop gui program using Visual C++ express 2008. In my Form1 constructor for my ref class Form1, I instantiate an instance of a class called MacroEditor. I want to create a delegate to one of my Form1 methods and pass that in as a parameter to the MacroEditor constructor to be used by macroEditor (the instantiated MacroEditor) as a callback method. Please show me, in great detail, how to create the delegate and pass it to the MacroEditor constructor. The method I want to delegate returns void and has 2 parameters; a String ^ and an int.
Thanks for any help you can provide.
This sounds like either C# or that MFC stuff not actual C++. As such I'm not familiar with the term "delegate", but it sounds like you want to pass the address of a function as an argument to the contructor of your class. Here is a link on how to do that: http://www.cplusplus.com/doc/tutorial/pointers/
It's the last entry in that page of the tutorial.
I am pretty sure it's C++/CLI when he did it with Visual Studio. MFC is actual C++ btw.
And madman, C++/CLI is NOT C++, just ignore the part before the slash. It's a different language. When you are seeking help for CLI, I am afraid you are wrong searching it in a C++ forum.
ah! ok! CLI not C++ Anyway, Computergeek01 is correct in assuming I want to pass a pointer to a function and "delegate" is the way I'm supposed to do it. Here is the closest I've found to doing what I want. http://msdn.microsoft.com/en-us/library/3z2x4f55%28VS.80%29.aspx
I think I'm halfway there. Progress is like continuously going halfway to the end - you get closer and closer but never really get there :-)
Thanks for your help.
That was a feature, not a bug. As I had written out C++/CLI like 3 or 4 times in this thread already, I thought by now it would be OK to assume the people know by now what I'm talking about.
Hanst, It was not meant as a dig at you, just reenforcing the points that have already been made.
Edit:
I know that I am being a bit picky here but when you have C++, CLI, and C++/CLI I do believe that it is important to use the correct one when making all references. Abbreviating C++/CLI should not be encouraged.