c++ - 类 Bar *bar 之类的指针的名称是什么

标签 c++ pointers forward-declaration

一个简单的例子:

void foo(class Bar * bar) {
    foo2(bar);
}

void foo2(Bar * bar) {
    bar->a++;
}

foo2 中使用的指针是指向类 Bar 的标准指针。 好的 - foo 中使用的指针也是指向类 Bar 的指针。但是这个地方一定不能知道类 Bar。

我找不到 foo 参数的正确命名。它是一个指向匿名类的指针? class Bar *bar 的正确名称是什么?

最佳答案

您需要的是前向声明

你可以阅读它in the documentationin a different post .

来自文档:

声明一个稍后将在此范围内定义的类类型。在定义出现之前,这个类名的类型是不完整的。这允许相互引用的类。

关于c++ - 类 Bar *bar 之类的指针的名称是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47902828/

相关文章:

c++ - 如何仅考虑 *pointer 中的前两个元素

c++ - 在一个 header 和一个 namespace 中堆叠多个前向声明

C++。 Child 继承自 Parent 并作为 Parent 属性包含在内

c++ - 提升构建 : disable -Weffc++ per module

C++ std::variant 与 std::any

c++ - 访问类数据时替代互斥锁定/解锁

c - 如果没有头文件,如何调用像 time() 这样的 C 函数?

c++ - 如何在谷歌基准测试中强制黑白输出

c - int *p; 有什么问题? *p=23;

c++ - & 和 * 之间的引用传递有什么区别?