简体   繁体   English

C ++ Unreal 4 - 指针语法

[英]C++ Unreal 4 - Pointer Syntax

I have doing some starting courses for UE4 Development, and I had a question relating to C++ usage in UE4. 我已经为UE4开发做了一些入门课程,我有一个与UE4中的C ++使用有关的问题。

I'm doing a tutorial to create a basic position reporter. 我正在做一个创建基本位置记者的教程。

Below is the peek definition of GetOwner() . 下面是GetOwner()的窥视定义。

FORCEINLINE_DEBUGGABLE class AActor* UActorComponent::GetOwner() const
{


    // During undo/redo the cached owner is unreliable so just used GetTypedOuter
    if (bCanUseCachedOwner)
    {
        checkSlow(OwnerPrivate == GetTypedOuter<AActor>()); // verify cached value is correct
        return OwnerPrivate;
    }
    else
    {
        return GetTypedOuter<AActor>();
    }

Could someone walk me through what the following line is doing exactly? 有人可以告诉我以下几行正是做什么的吗?

Is class AActor* grabbing the memory address of AActor? class AActor*抓住了class AActor*的内存地址? Or is it creating a pointer? 还是它创建一个指针?

I know the basics of pointers (pointer POINTS to memory address of something, can be dereferenced), just having trouble wrapping my mind around this section. 我知道指针的基础知识(指针点到某些内存地址的指针,可以解除引用),只是在我的脑海中绕过这部分时遇到了麻烦。

FORCEINLINE_DEBUGGABLE class AActor* UActorComponent::GetOwner() const

I'm seeing a lot of these in various parts of the UE4 source code, such as in UObjectBase, so I am trying to figure out these all out. 我在UE4源代码的各个部分看到了很多这些,比如在UObjectBase中,所以我试图弄清楚这些。

UObjectBase::UObjectBase(UClass* InClass, EObjectFlags InFlags, EInternalObjectFlags InInternalFlags, UObject *InOuter, FName InName)
:   ObjectFlags         (InFlags)
,   InternalIndex       (INDEX_NONE)
,   ClassPrivate        (InClass)
,   OuterPrivate        (InOuter)
{
    check(ClassPrivate);
    // Add to global table.
    AddObject(InName, InInternalFlags);
}

Skipping the debugging macro, the rest of the line 跳过调试宏,其余部分

class AActor* UActorComponent::GetOwner() const

is just a complicated way of forward declaring a class type and using that in a return value. 只是一种前向声明类类型并在返回值中使用它的复杂方法。

I would write this in two parts: 我会把它写成两部分:

class AActor;   // forward declare class type

AActor* UActorComponent::GetOwner() const;

A pointer to a class object can be returned (or used as a parameter) without knowing what the class looks like, but it cannot be used otherwise until the full class declaration is seen. 可以返回(或用作参数)指向类对象的指针,而不知道类的外观,但在看到完整的类声明之前不能使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM