I am looking to call a method with a dictionary I am coming from c# and just getting into C++. I have looked around and cant seem to fully understand the logic, the code I am looking to replicate is c#:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
void Main()
{
dicMyDictonary = new Dictionary<string, Delegate>()
{
{"myString", new Func<MyClass, int, int>(MyMethod)}
}
}
void Run(string s)
{
var res = dicMyDictonary[s].DynamicInvoke(this, 21);
}
voidint MyMethod(MyClass, int arg1)
{
//blah
}
Quick question for you JLBorgs, I am trying to add to the Dictionary but I am getting an error 'error: 'dicMyDictonary' does not name a type': dicMyDictonary->Add( "Call Second Method", &my_class::SecondMethod
I think I understand what the code is doing but if I can't add a index into the dictionary I don't know if I am fully understanding it.
my_class mc ; // to access the non-static member, an object is required
mc.dicMyDictonary[ "Call Second Method" ] = &my_class::SecondMethod ;
// or: mc.dicMyDictonary.emplace( "Call Second Method", &my_class::SecondMethod ) ;
I have been wrestling with "my_class::dicMyDictonary': list initialization inside member initializer list or non-static data member initializer is not implemented
"
Can you tell me what this is? I am trying to build it for universal 10...
Gah, I am not liking C++...
Now, to keep to the question: I have been wrestling with
"my_class::dicMyDictonary': list initialization inside member initializer list or non-static data member initializer is not implemented
"
Can you tell me what can fix this? I dont understand why I need to initilize it inside of a class and not a struct, I am trying to build it for universal windows 10...