【虚幻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();
};
相关推荐
旅僧15 分钟前
机械臂学习笔记(更新中)
笔记·学习
qingwufeiyang_53027 分钟前
Python学习笔记3-项目实战-AI应用
笔记·学习
代码中介商34 分钟前
C++ 智能指针完全指南(二):shared_ptr 深度详解
开发语言·c++
智者知已应修善业35 分钟前
【proteus 74160实现模60计数器模41计数器】2024-5-27
驱动开发·经验分享·笔记·硬件架构·proteus·硬件工程
WWW652642 分钟前
代码随想录 打卡第五十四天
数据结构·c++·算法
墨白曦煜44 分钟前
算法实战笔记:空间换时间的黑魔法——单调栈全景解析(十一)
java·笔记·算法
问心无愧05131 小时前
ctf show web入门157 158
前端·笔记
闪闪发亮的小星星1 小时前
STK-03-通信卫星方向最常遇到的场景
笔记
redaijufeng1 小时前
我在C++中深入理解了继承,收获颇丰
java·c++·算法
.千余1 小时前
【C++】C++继承入门(上):继承语法与基本特性详解
开发语言·c++·笔记·学习·其他