【虚幻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();
};
相关推荐
byte轻骑兵1 小时前
【Bluedroid】蓝牙HID DEVICE断开连接流程源码分析
android·c++·蓝牙·hid·bluedroid
修修修也2 小时前
【C++】特殊类设计
开发语言·c++·特殊类·类与对象
Alessio Micheli2 小时前
国债收益率、需求与抛售行为的逻辑解析
笔记
虾球xz2 小时前
游戏引擎学习第274天:基于弹簧的动态动画
c++·学习·游戏引擎
byte轻骑兵3 小时前
【C++重载操作符与转换】转换与继承
开发语言·c++
筏.k3 小时前
C++ asio网络编程(4)异步读写操作及注意事项
服务器·网络·c++
weixin_1103 小时前
Qt 无边框窗口,支持贴边分屏
c++·qt
梭七y4 小时前
记录学习《手动学习深度学习》这本书的笔记(十一)
笔记·深度学习·学习
Cuit小唐4 小时前
C++ 组合模式详解
开发语言·c++·组合模式
hallo-ooo4 小时前
【C/C++】const关键词及拓展
c语言·c++