【虚幻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();
};
相关推荐
Lzg_na12 分钟前
订阅发布模块事例
c++
sulikey25 分钟前
个人Linux操作系统学习笔记11 - 环境变量
linux·笔记·学习
汉克老师26 分钟前
2026年CSP-J初赛分数线-----预测
c++·csp-j·小学生·学c++编程
脱胎换骨-军哥27 分钟前
C++数据库存储引擎内核开发:B+树索引与MVCC并发控制的完整实现
数据库·c++·b树
小保CPP1 小时前
OpenCV C++将多张图像合并为webp动图
c++·人工智能·opencv·计算机视觉
依然范特东1 小时前
强化学习笔记2--bellman equation
人工智能·笔记
乐观勇敢坚强的老彭2 小时前
信奥C++一维数组笔记
开发语言·c++·笔记
码上有光2 小时前
异常和智能指针
java·大数据·c++·servlet·异常·智能指针
王维同学2 小时前
[原创][Windows C++]Explorer Shell 扩展、图标覆盖与 COM 服务器定位
c++·windows·注册表
昕光xg2 小时前
Istio笔记04-基于Jaeger的分布式链路追踪
笔记·分布式·istio