【虚幻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();
};
相关推荐
yi01125 分钟前
DAY27: LeetCode 110. 平衡二叉树 | 在递归中判断是否平衡
人工智能·笔记·python·算法·leetcode·二叉树·递归
SWAGGY..1 小时前
【C++进阶】:(10)哈希表的原理与实现——从哈希函数到哈希桶
c++·哈希算法·散列表
码匠许师傅1 小时前
【C++三方组件】redis-plus-plus:现代 Redis C++ 客户端
java·c++·redis
ab1237681 小时前
MQTT笔记
java·笔记·mqtt·学习
wuminyu1 小时前
stackChunkOop内部结构与GC屏障的配合工作原理剖析
java·linux·c语言·jvm·c++
小π军1 小时前
C 和 C++ 是否都支持函数的重载?
java·c语言·c++
sunoo-2291 小时前
嵌入式Linux驱动学习笔记(第3-6天):从misc封装、platform总线到设备树、中断与单总线外设实战
linux·arm开发·驱动开发·笔记·单片机·学习
烟花落o1 小时前
C++ 从 C 到进阶 ④:类和对象(下)—— 构造函数进阶、static、友元与内部类
c++·类和对象·初始化列表·匿名对象·内部类·友元函数·static成员函数
自不量力的A同学1 小时前
MooTool Next 1.3.0 发布
笔记
stellanke1 小时前
工业化C++:3. 继承、虚函数与运行时多态:从水果加工到日志策略设计
开发语言·c++