Yes, that is the correct syntax to create a C++/CLI static constructor. You can know its not creating a static function since that is not a valid function declaration syntax. Functions must have the return type specified. Also, the compiler would complain that Foo()
is not a member of class Foo if it weren't linking it to the constructor you declared in the class definition.
You can test the fairly easily:
using namespace System;
ref class Foo {
static Foo();
Foo();
}
static Foo::Foo() { Console.WriteLine("Static Constructor"); }
Foo::Foo() { Console.WriteLine("Constructor"); }
int main(array<System::String ^> ^args)
{
Foo ^f = gcnew Foo();
Console.WriteLine("Main");
}
This would output:
Static Constructor
Constructor
Main