【虚幻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();
};
相关推荐
Cx330❀34 分钟前
《C++ STL:vector类(上)》:详解基础使用&&核心接口及经典算法题
开发语言·c++·经验分享·算法
HELLOMILI1 小时前
[UnrealEngine] 虚幻编辑器界面 | 虚幻界面详解 | UE5界面详解
游戏·ue5·编辑器·游戏引擎·虚幻·unreal engine
hqwest2 小时前
QT肝8天13--删除用户
开发语言·c++·qt·csdn开发云·列表分页·qt分页
聪明的笨猪猪2 小时前
Java 高并发多线程 “基础”面试清单(含超通俗生活案例与深度理解)
java·经验分享·笔记·面试
奔跑吧邓邓子4 小时前
【C++实战(64)】C++ 邂逅SQLite3:数据库编程实战之旅
数据库·c++·sqlite·实战·sqlite3·数据库编程
会开花的二叉树4 小时前
RabbitMQ C++ 客户端封装与实战
c++·rabbitmq·ruby
我命由我123457 小时前
Photoshop - Photoshop 工具从工具栏消失
笔记·学习·ui·职场和发展·职场发展·photoshop·ps
Vect__7 小时前
从直线到环形:解锁栈、队列背后的空间与效率平衡术
数据结构·c++
头发还没掉光光9 小时前
C++STL之list
c语言·数据结构·c++·list
我笑了OvO10 小时前
C++类和对象(1)
java·开发语言·c++·类和对象