在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)