방법: 인터페이스 정적 생성자 정의(C++/CLI)
An interface can have a static constructor, which can be used to initialize static data members. A static constructor will be called at most once, and will be called before the first time a static interface member is accessed.
For more information on static constructors, see 방법: 클래스 또는 구조체에서 정적 생성자를 정의 합니다..
예제
// mcppv2_interface_class2.cpp
// compile with: /clr
using namespace System;
interface struct MyInterface {
static int i;
static void Test() {
Console::WriteLine(i);
}
static MyInterface() {
Console::WriteLine("in MyInterface static constructor");
i = 99;
}
};
ref class MyClass : public MyInterface {};
int main() {
MyInterface::Test();
MyClass::MyInterface::Test();
MyInterface ^ mi = gcnew MyClass;
mi->Test();
}