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

C++ Equivalent to Java Static Initializers

The C++ equivalent to a Java static initializer block uses a private nested class.

Java C++
class Foo
{
    public static int field;

    static
    {
        field = 1;
    }
}
class Foo
{
public:
    static int field;

private:
    class StaticConstructor
    {
    public:
        StaticConstructor()
        {
            field = 1;
        }
    };

private:
    static Foo::StaticConstructor staticConstructor;
};


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

Additional resource: Java and C++ Equivalents


Copyright © 1997 – 2017 Tangible Software Solutions Inc.