【虚幻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();
};
相关推荐
靡樊12 分钟前
Socket编程UDP\TCP
网络·c++·学习·tcp/ip·udp
东京老树根21 分钟前
SAP学习笔记 - 开发24 - 前端Fiori开发 Filtering(过滤器),Sorting and Grouping(排序和分组)
笔记·学习
byte轻骑兵40 分钟前
【C++高级主题】命令空间(五):类、命名空间和作用域
开发语言·c++
忘梓.1 小时前
从二叉树到 STL:揭开 set 容器的本质与用法
开发语言·c++
Alan3162 小时前
qt network 整体框架
c++
100分题库小程序2 小时前
汽车加气站操作工证考试重点
经验分享·笔记·安全
byte轻骑兵2 小时前
【C++高级主题】虚基类的声明
开发语言·c++
落羽的落羽2 小时前
【C++】二叉搜索树
开发语言·数据结构·c++·学习
胡译胡说2 小时前
C语言的”代码化石“出土:1979年的英文文本判别器
c++·unix
偷懒下载原神3 小时前
《C++ 模板》
开发语言·c++