방법: 인터페이스 정적 생성자 정의(C++/CLI)
인터페이스에는 정적 데이터 멤버를 초기화하는 데 사용할 수 있는 정적 생성자가 있을 수 있습니다. 정적 생성자는 최대 한 번 호출되며 정적 인터페이스 멤버에 처음 액세스하기 전에 호출됩니다.
예시
// 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();
}
in MyInterface static constructor
99
99
99
참고 항목
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기