diff --git a/src/AST/Class.cs b/src/AST/Class.cs index 30c4adaf..a9601dd7 100644 --- a/src/AST/Class.cs +++ b/src/AST/Class.cs @@ -213,7 +213,7 @@ namespace CppSharp.AST public Method GetRootBaseMethod(Method @override, bool onlyFirstBase = false) { return (from @base in Bases - where !onlyFirstBase || !@base.Class.IsInterface + where @base.IsClass && (!onlyFirstBase || !@base.Class.IsInterface) let baseMethod = ( from method in @base.Class.Methods where diff --git a/src/Generator/Generators/CLI/CLISourcesTemplate.cs b/src/Generator/Generators/CLI/CLISourcesTemplate.cs index 9bb47ef0..1dbe96ee 100644 --- a/src/Generator/Generators/CLI/CLISourcesTemplate.cs +++ b/src/Generator/Generators/CLI/CLISourcesTemplate.cs @@ -545,7 +545,7 @@ namespace CppSharp.Generators.CLI private bool GenerateClassConstructorBase(Class @class, bool isIntPtr, Method method = null) { - var hasBase = @class.HasBase && !@class.Bases[0].Class.Ignore; + var hasBase = @class.HasBase && @class.Bases[0].IsClass && !@class.Bases[0].Class.Ignore; if (!hasBase) return false; diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 6760952e..2c2770c0 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -716,6 +716,7 @@ namespace CppSharp.Generators.CSharp { bases.AddRange( from @base in @class.Bases + where @base.IsClass select QualifiedIdentifier(@base.Class)); } diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h index 78ecdcde..7cbfba3f 100644 --- a/tests/Basic/Basic.h +++ b/tests/Basic/Basic.h @@ -153,3 +153,14 @@ struct DLL_API DefaultParameters void Bar() const; void Bar(); }; + +// The Curiously Recurring Template Pattern (CRTP) +template +class Base +{ + // methods within Base can use template to access members of Derived + Derived* create() { return new Derived(); } +}; +class Derived : public Base +{ +};