• Saves Valuable Time
  • Trusted Accuracy for 12 Years
  • 15-Day Money-Back Guarantee

C++ Equivalent to VB Extension Methods

C++ doesn't have extension methods, so a VB extension method is just converted to an ordinary C++ static method (calls to the method have to be adjusted to static calls using the class name).

VB C++
Public Module ContainsExtension
    <System.Runtime.CompilerServices.Extension> _
    Public Sub ExtensionMethod(ByVal myParam As String)
        '...
    End Sub
End Module
Friend Class TestClass
    Private Sub TestMethod()
        Dim s As String
        s.ExtensionMethod()
    End Sub
End Class
#include <string>

class ContainsExtension final
{
public:
    static void ExtensionMethod(const std::string &myParam)
    {
        //...
    }
};
class TestClass
{
private:
    void TestMethod()
    {
        std::string s = "";
        ContainsExtension::ExtensionMethod(s);
    }
};


Use VB to C++ Converter to convert from VB to C++.     

Additional resource: VB.NET and C++ Equivalents


Copyright © 1997 – 2017 Tangible Software Solutions Inc.