欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 八卦 > 【虚幻C++笔记】接口

【虚幻C++笔记】接口

2025/4/19 8:34:33 来源:https://blog.csdn.net/OSwich/article/details/147264651  浏览:    关键词:【虚幻C++笔记】接口

目录

  • 概述
  • 创建接口

概述

  • 简单的说,接口提供一组公共的方法,不同的对象中继承这些方法后可以有不同的具体实现。
  • 任何使用接口的类都必须实现这些接口。
  • 实现解耦
  • 解决多继承的问题

创建接口

在这里插入图片描述

// 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();
};

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词