【虚幻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();
};
相关推荐
一定要AK3 小时前
Spring 入门核心笔记
java·笔记·spring
研究点啥好呢3 小时前
Github热门项目推荐 | 创建你的像素风格!
c++·python·node.js·github·开源软件
_dindong3 小时前
cf1091div2 C.Grid Covering(数论)
c++·算法
沫璃染墨3 小时前
C++ string 从入门到精通:构造、迭代器、容量接口全解析
c语言·开发语言·c++
6Hzlia3 小时前
【Hot 100 刷题计划】 LeetCode 17. 电话号码的字母组合 | C++ 回溯算法经典模板
c++·算法·leetcode
_李小白4 小时前
【OSG学习笔记】Day 38: TextureVisitor(纹理访问器)
android·笔记·学习
计算机安禾4 小时前
【数据结构与算法】第36篇:排序大总结:稳定性、时间复杂度与适用场景
c语言·数据结构·c++·算法·链表·线性回归·visual studio
unicrom_深圳市由你创科技4 小时前
做虚拟示波器这种实时波形显示的上位机,用什么语言?
c++·python·c#
无限进步_4 小时前
【C++】电话号码的字母组合:从有限处理到通用解法
开发语言·c++·ide·windows·git·github·visual studio
C++ 老炮儿的技术栈5 小时前
GCC编译时无法向/tmp 目录写入临时汇编文件,因为设备空间不足,解决
linux·运维·开发语言·汇编·c++·git·qt