【虚幻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();
};
相关推荐
weixin_307779139 分钟前
设计Mock华为昇腾GPU的MindSpore和CANN的库的流程与实现
c++·算法·华为·系统架构·gpu算力
智者知已应修善业1 小时前
【c#窗体荔枝计算乘法,两数相乘】2022-10-6
经验分享·笔记·算法·c#·.net
嗯诺1 小时前
切换python多版本
笔记·python
桂萍1 小时前
realIADD3复现笔记
笔记
kk”2 小时前
C++ 模板初阶
开发语言·c++
仟濹4 小时前
【C/C++】整数超过多少位时用「高精度」
c语言·c++·算法
新手小新8 小时前
C++游戏开发(2)
开发语言·前端·c++
程序员编程指南10 小时前
Qt 嵌入式界面优化技术
c语言·开发语言·c++·qt
【上下求索】10 小时前
学习笔记090——Ubuntu 中 UFW 防火墙的使用
笔记·学习·ubuntu
NeRF_er11 小时前
STORM代码阅读笔记
大数据·笔记·storm