【虚幻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();
};
相关推荐
青梅味猪大肠2 小时前
【深入浅出C++】为什么虚表指针可以解决菱形继承
开发语言·c++
Lhan.zzZ2 小时前
QML 组件库:VS2022 + Qt 静态库方案
开发语言·c++·qt·visual studio
Huathy-雨落江南,浮生若梦3 小时前
Caddy 学习笔记 - 反向代理与 IP 封禁
笔记·学习·tcp/ip
谢白羽4 小时前
SGLang的AWQ量化笔记
笔记·python·sglang
噜~噜~噜~4 小时前
操作系统笔记-2.3.5.2 读者-写者问题
笔记·操作系统
一木 之林5 小时前
五、C++ 新特性、关键字与编译原理(进阶)(二)
java·开发语言·c++
OPEN-F5 小时前
C++11/14新特性精讲:移动语义与智能指针实战
开发语言·c++·算法
闭月之泪舞5 小时前
C++编程学习
c++·学习
MindUp5 小时前
企业私有化文件管理系统选型实录:从部署架构到AI能力的技术调研笔记
人工智能·笔记·架构
GGMM7896 小时前
西门子BOP20基本操作面板超详细教程(S120/G130专用)
笔记·变频器·变频器维修