diff --git a/src/Generator/AST/VTables.cs b/src/Generator/AST/VTables.cs index 31a7689b..da965a99 100644 --- a/src/Generator/AST/VTables.cs +++ b/src/Generator/AST/VTables.cs @@ -72,13 +72,21 @@ namespace CppSharp.AST throw new NotSupportedException(); } - public static int GetVTableIndex(INamedDecl method, Class @class) + static bool CanOverride(Method method, Method @override) + { + return method.OriginalName == @override.OriginalName && + method.ReturnType == @override.ReturnType && + method.Parameters.SequenceEqual(@override.Parameters, + new ParameterTypeComparer()); + } + + public static int GetVTableIndex(Method method, Class @class) { switch (@class.Layout.ABI) { case CppAbi.Microsoft: return (from table in @class.Layout.VFTables - let j = table.Layout.Components.FindIndex(m => m.Method == method) + let j = table.Layout.Components.FindIndex(m => CanOverride(m.Method, method)) where j >= 0 select j).First(); default: diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index c6864876..482a1aeb 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -2329,7 +2329,7 @@ namespace CppSharp.Generators.CSharp out string delegateId) { var virtualCallBuilder = new StringBuilder(); - var i = VTables.GetVTableIndex(function.OriginalFunction, @class); + var i = VTables.GetVTableIndex(function.OriginalFunction as Method, @class); virtualCallBuilder.AppendFormat("void* slot = *(void**) ((({0}.Internal*) {1})->vfptr0 + {2} * {3});", @class.Name, Helpers.InstanceIdentifier, i, Driver.TargetInfo.PointerWidth / 8); virtualCallBuilder.AppendLine();