【虚幻C++笔记】接口

目录

概述

  • 简单的说,接口提供一组公共的方法,不同的对象中继承这些方法后可以有不同的具体实现。
  • 任何使用接口的类都必须实现这些接口。
  • 实现解耦
  • 解决多继承的问题

创建接口

cpp 复制代码
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "MyInterface.generated.h"

// This class does not need to be modified.
UINTERFACE(MinimalAPI)
class UMyInterface : public UInterface
{
	GENERATED_BODY()
};

/**
 * 
 */
class GENERALFRAMEWORK_API IMyInterface
{
	GENERATED_BODY()

	// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
// 纯虚函数,实现类必须实现接口
	virtual void MyInterface_PureVirtual() = 0;
 
	// 虚函数,在接口本身的 .h 或 .cpp 文件中提供默认实现.实现类可覆盖
	virtual void MyInterface_Virtual();
 
	//实现类可以在蓝图和C++中实现接口
	UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
	void MyInterface_NativeEvent1(int32 number);
	
	//实现类在蓝图中实现接口
	UFUNCTION(BlueprintCallable, BlueprintImplementableEvent)
	void MyInterface_ImplementableEvent();
};
相关推荐
码途漫谈6 小时前
Easy-Vibe开发篇阅读笔记(四)——前端开发之结合 Agent Skills 美化界面
人工智能·笔记·ai·开源·ai编程
c++之路8 小时前
C++信号处理
开发语言·c++·信号处理
糖炒栗子03269 小时前
【笔记】高分卫星影像 TIF 切片处理
笔记
Nice_Fold9 小时前
Kubernetes DaemonSet、StatefulSet与Service(自用笔记)
笔记·容器·kubernetes
故事还在继续吗10 小时前
C++20关键特性
开发语言·c++·c++20
青少儿编程课堂11 小时前
2026青少儿信息素养大赛备赛指南!Python/Scratch/C++备考要点
开发语言·c++·python
旖-旎11 小时前
深搜练习(电话号码字母组合)(3)
c++·算法·力扣·深度优先遍历
AIFarmer11 小时前
【无标题】
开发语言·c++·算法
John_ToDebug12 小时前
WebHostView 与 TabStrip 交互机制深度解析
c++·chrome·windows
ZhiqianXia12 小时前
《The Design of Design》阅读笔记
前端·笔记·microsoft