gpt4 book ai didi

c++ - 参数前的 "class"是什么意思?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:13:21 26 4
gpt4 key购买 nike

虚幻引擎生成以下函数:

void AFlyingPawn::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
//stuff...
}

请注意参数类型之前的“类”说明符。什么意思?

最佳答案

<强>1。第一种可能性,这可能是一个forward declarations ,如果 UInputComponent 之前没有声明。所以

void AFlyingPawn::SetupPlayerInputComponent(class UInputComponent* InputComponent)

forward声明了一个名为UInputComponent的类,参数InputComponent的类型为UInputComponent*

Note that a new class name may also be introduced by an elaborated type specifier which appears as part of another declaration, but only if name lookup can't find a previously declared class with the same name.

class U;
namespace ns{
class Y f(class T p); // declares function ns::f and declares ns::T and ns::Y
class U f(); // U refers to ::U
Y* p; T* q; // can use pointers and references to T and Y
}

<强>2。第二possibility ,关键字 class 可用于消除歧义。

If a function or a variable exists in scope with the name identical to the name of a class type, class can be prepended to the name for disambiguation, resulting in an elaborated type specifier

例如

int UInputComponent;
class UInputComponent { /* ... */ };

// without the class keyword it won't compile because the name UInputComponent is ambiguous
void AFlyingPawn::SetupPlayerInputComponent(class UInputComponent* InputComponent)

<强>3。第三种可能,它可能没有任何意义。

如果 UInputComponent 已声明为类,则使用或不使用关键字 class 都不会改变任何内容。请注意,如果先前声明的类型不匹配,则编译将失败。

关于c++ - 参数前的 "class"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41312056/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com