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

C++ Equivalent to C# Constructors & Finalizers

A C# finalizer uses the '~' operator, but is not equivalent to a C++ destructor. The implementation of the 'Dispose' method in the IDisposable interface can be converted to a C++ destructor, but this is not exactly equivalent.

C# C++
class Foo: System.IDisposable
{
    public Foo() : this(0)   //call to other constructor
    {
    }
    public Foo(int i)
    {
    }

    public void Dispose()
    {
    }

    ~Foo()   //'finalizer' method
    {
    }
}
class Foo
{
public:
    Foo() : Foo(0)   //call to other constructor
    {
    }
    Foo(int i)
    {
    }

    ~Foo()   //destructor
    {
    }

private:
//C# TO C++ CONVERTER WARNING: Unlike C#, there is no automatic call to this finalizer method in native C++:
    void Finalize()
    {
    }
};


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

Additional resource: C++ and C# Equivalents


Copyright © 1997 – 2017 Tangible Software Solutions Inc.