小编Jon*_*han的帖子

为什么在C ++中的类指针声明中使用'struct'关键字

在C ++中声明类指针变量时,何时以及为什么我们应该使用'struct'关键字?

我已经在嵌入式环境中看到了这一点,所以我怀疑这是C的一种保留。我已经看到了很多有关在声明struct对象时何时使用'struct'关键字的解释,因为它与C中的名称空间相关(在这里),但是我找不到任何人在谈论为什么在声明类指针变量时可能会使用它。

例如,在CFoo.h中:

class CFoo
{
public:
    int doStuff();
};

inline Foo::doStuff()
{
    return 7;
}
Run Code Online (Sandbox Code Playgroud)

后来在另一个类中:

void CBar::interesting()
{
    struct CFoo *pCFoo;

    // Go on to do something interesting with pCFoo...
}
Run Code Online (Sandbox Code Playgroud)

c++ variables scope class elaboration

2
推荐指数
2
解决办法
118
查看次数

标签 统计

c++ ×1

class ×1

elaboration ×1

scope ×1

variables ×1