gpt4 book ai didi

c++ - “class classname* funcname(void) ”在C++中是什么意思?

转载 作者:行者123 更新时间:2023-12-03 06:49:19 28 4
gpt4 key购买 nike

我在头文件中找到以下代码,并且在另一个头文件中定义了“BOOT”类。

class BOOT* boot(void);
它看起来像一个函数的声明,但它以 class开头。

最佳答案

这是一个详细的类型说明符:

Elaborated type specifiers may be used to refer to a previously-declared class name (class, struct, or union) or to a previously-declared enum name even if the name was hidden by a non-type declaration. They may also be used to declare new class names.


https://en.cppreference.com/w/cpp/language/elaborated_type_specifier
取自Artefacto和dfrib的答案,因为它使重点指向:它等效于:
class BOOT;
BOOT* boot(void);
在您的示例中,如果尚不知道,它实际上会对BOOT类进行前向声明。在同一页面上查看此示例 struct Data* Data;:
struct Node {
struct Node* Next; // OK: lookup of Node finds the injected-class-name
struct Data* Data; // OK: declares type Data at global scope
// and also declares the data member Data
friend class ::List; // error: cannot introduce a qualified name
enum Kind* kind; // error: cannot introduce an enum
};

Data* p; // OK: struct Data has been declared

关于c++ - “class classname* funcname(void) ”在C++中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64801243/

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