【虚幻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();
};
相关推荐
saltymilk4 分钟前
C++ 使用分治减小模板递归深度
c++
悠哉清闲1 小时前
C ++代码学习笔记(一)
c++·笔记·学习
YxVoyager2 小时前
【C标准库】详解<stdio.h>标准输入输出库
c语言·c++
希望_睿智2 小时前
实战设计模式之解释器模式
c++·设计模式·架构
Demonsong_3 小时前
2025.8.22周五 在职老D渗透日记day24:burp+mumu抓包 安卓7.0以上证书配置
经验分享·笔记
海鸥_3 小时前
C++中不加{}导致的BUG
c++·bug
MowenPan19953 小时前
高等数学 9.1多元函数的基本概念
笔记·学习·高等数学
努力努力再努力wz5 小时前
【c++进阶系列】:万字详解多态
java·linux·运维·开发语言·c++
qq_341160446 小时前
文件系统挂载详细分析(《图解Linux内核》虚拟文件系统篇笔记二)
linux·服务器·笔记
NuyoahC6 小时前
笔试——Day46
c++·算法·笔试