다음을 통해 공유


interface 클래스(C++ 구성 요소 확장)

인터페이스를 선언합니다.기본 인터페이스에 대 한 자세한 내용은 __interface.

모든 런타임

구문

interface_access interface class  name :  inherit_access base_interface {};
interface_access interface struct name :  inherit_access base_interface {};

매개 변수

  • interface_access
    어셈블리 외부 인터페이스의 내게 필요한 옵션입니다.가능한 값은 public 및 private.private가 기본값입니다.중첩된 인터페이스를 가질 수 없습니다는 interface_access 지정자입니다.

  • name
    인터페이스의 이름입니다.

  • inherit_access
    액세스 가능성을 base_interface.경우에 허용 내게 필요한 옵션의 기본 인터페이스에 대 한 public (기본값).

  • base_interface (옵션)
    인터페이스에 대 한 기본 인터페이스 이름.

설명

구조체 인터페이스 입니다 인터페이스 클래스.

인터페이스 선언이 함수, 이벤트 및 속성을 포함할 수 있습니다.모든 인터페이스 멤버는 공용으로 액세스할을 수 있습니다.인터페이스는 정적 데이터 멤버, 함수, 이벤트 및 속성에도 포함할 수 있으며 이러한 정적 멤버는 인터페이스에 정의 되어야 합니다.

인터페이스를 정의 하 여 어떻게 클래스를 구현할 수 있습니다.인터페이스를 사용할 수 없습니다. 클래스 및 클래스는 인터페이스를 구현할 수 있습니다.클래스 인터페이스에 선언 된 함수를 정의 하는 경우 재정의 함수 구현 됩니다.따라서 이름 조회 인터페이스 멤버는 포함 되지 않습니다.

클래스 또는 구조체가 인터페이스를 상속 하는 인터페이스의 모든 멤버를 구현 해야 합니다.인터페이스를 구현 하는 경우 이름 또한 인터페이스를 구현 해야는 base_interface 목록입니다.

자세한 내용은 다음을 참조하십시오.

다른 CLR 형식에 대 한 자세한 내용은 클래스 및 구조체.

이 인터페이스와 형식인 경우 컴파일할 때 검색할 수 있습니다 __is_interface_class(type).자세한 내용은 형식 특성에 대한 컴파일러 지원(C++ 구성 요소 확장)를 참조하십시오.

개발 환경에서 F1 도움말에 이러한 키워드는 키워드를 강조 표시 하 여 까 (interface class, 예를 들어) 및 F1 키를 누르면 됩니다.

Windows 런타임

설명

(만 Windows 런타임에 적용 없음이 언어 기능에 대 한 설명입니다.)

737cydt1.collapse_all(ko-kr,VS.110).gif요구 사항

컴파일러 옵션:/ZW

공용 언어 런타임

설명

(공용 언어 런타임만을 적용 없음이 언어 기능에 대 한 설명입니다.)

737cydt1.collapse_all(ko-kr,VS.110).gif요구 사항

컴파일러 옵션:/clr

737cydt1.collapse_all(ko-kr,VS.110).gif예제

예제

다음 코드 예제에서는 인터페이스를 사용 하 여 시계 함수의 동작을 정의 하는 수 있습니다 하는 방법을 보여 줍니다.

// mcppv2_interface_class.cpp
// compile with: /clr
using namespace System;

public delegate void ClickEventHandler(int, double);

// define interface with nested interface
public interface class Interface_A {
   void Function_1();

   interface class Interface_Nested_A {
      void Function_2();
   };
};

// interface with a base interface
public interface class Interface_B : Interface_A {
   property int Property_Block;
   event ClickEventHandler^ OnClick;   
   static void Function_3() { Console::WriteLine("in Function_3"); }
};

// implement nested interface
public ref class MyClass : public Interface_A::Interface_Nested_A {
public:
   virtual void Function_2() { Console::WriteLine("in Function_2"); }
};

// implement interface and base interface
public ref class MyClass2 : public Interface_B {
private:
   int MyInt;

public:
   // implement non-static function
   virtual void Function_1() { Console::WriteLine("in Function_1"); }

   // implement property
   property int Property_Block {
      virtual int get() { return MyInt; }
      virtual void set(int value) { MyInt = value; }
   }
   // implement event
   virtual event ClickEventHandler^ OnClick;

   void FireEvents() {
      OnClick(7, 3.14159);
   }
};

// class that defines method called when event occurs
ref class EventReceiver {
public:
   void OnMyClick(int i, double d) {
      Console::WriteLine("OnClick: {0}, {1}", i, d);
   }
};

int main() {
   // call static function in an interface
   Interface_B::Function_3();

   // instantiate class that implements nested interface
   MyClass ^ x = gcnew MyClass;
   x->Function_2();

   // instantiate class that implements interface with base interface
   MyClass2 ^ y = gcnew MyClass2;
   y->Function_1();
   y->Property_Block = 8;
   Console::WriteLine(y->Property_Block);

   EventReceiver^ MyEventReceiver = gcnew EventReceiver();

   // hook handler to event
   y->OnClick += gcnew ClickEventHandler(MyEventReceiver, &EventReceiver::OnMyClick);

   // invoke events
   y->FireEvents();

   // unhook handler to event
   y->OnClick -= gcnew ClickEventHandler(MyEventReceiver, &EventReceiver::OnMyClick);

   // call implemented function via interface handle
   Interface_A^ hi = gcnew MyClass2();
   hi->Function_1();
}

Output

  
  
  
  
  
  

예제

다음 코드 샘플에서는 서명이 같은 선언에서 여러 인터페이스 및 클래스에서 인터페이스를 사용 하는 함수를 구현 하는 두 가지 방법을 보여 줍니다.

// mcppv2_interface_class_2.cpp
// compile with: /clr /c
interface class I {
   void Test();
   void Test2();
};

interface class J : I {
   void Test();
   void Test2();
};

ref struct R : I, J {
   // satisfies the requirement to implement Test in both interfaces
   virtual void Test() {}

   // implement both interface functions with explicit overrides
   virtual void A() = I::Test2 {}
   virtual void B() = J::Test2 {}
};

참고 항목

개념

런타임 플랫폼의 구성 요소 확장