UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DefinePrivateMemberPtr.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
7
8namespace UE::Core::Private
9{
10 template <auto Storage, auto PtrToMember>
12 {
14 {
15 *Storage = PtrToMember;
16 }
17
19 };
20
21 template <auto Storage, auto PtrToMember>
23}
24
25// A way to get a pointer-to-member of private members of a class without explicit friendship.
26// It can be used for both data members and member functions.
27//
28// Use of this macro for any purpose is at the user's own risk and is not supported.
29//
30// Example:
31//
32// struct FPrivateStuff
33// {
34// explicit FPrivateStuff(int32 InVal)
35// {
36// Val = InVal;
37// }
38//
39// private:
40// int32 Val;
41//
42// void LogVal() const
43// {
44// UE_LOG(LogTemp, Log, TEXT("Val: %d"), Val);
45// }
46// };
47//
48// // These should be defined at global scope
49// UE_DEFINE_PRIVATE_MEMBER_PTR(int32, GPrivateStuffValPtr, FPrivateStuff, Val);
50// UE_DEFINE_PRIVATE_MEMBER_PTR(void() const, GPrivateStuffLogVal, FPrivateStuff, LogVal);
51//
52// FPrivateStuff Stuff(5);
53//
54// (Stuff.*GPrivateStuffLogVal)(); // Logs: "Val: 5"
55// Stuff.*GPrivateStuffValPtr = 7;
56// (Stuff.*GPrivateStuffLogVal)(); // Logs: "Val: 7"
57//
58#define UE_DEFINE_PRIVATE_MEMBER_PTR(Type, Name, Class, Member) \
59 TIdentity_T<PREPROCESSOR_REMOVE_OPTIONAL_PARENS(Type)> PREPROCESSOR_REMOVE_OPTIONAL_PARENS(Class)::* Name; \
60 template struct UE::Core::Private::TPrivateAccess<&Name, &PREPROCESSOR_REMOVE_OPTIONAL_PARENS(Class)::Member>
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
implementation
Definition PlayInEditorLoadingScope.h:8
Definition DefinePrivateMemberPtr.h:12
TPrivateAccess()
Definition DefinePrivateMemberPtr.h:13
static TPrivateAccess Instance
Definition DefinePrivateMemberPtr.h:18