在C.
struct node {
int x;
};
node *y; // incorrect
struct node *y; // correct
Run Code Online (Sandbox Code Playgroud)
在C++中
struct node{
int x;
};
node *y; // correct
y = new node; // correct
Run Code Online (Sandbox Code Playgroud)
问题:为什么标签名称在C++中不在C中创建指针是可以接受的?
因为C++标准是这样说的,而C标准则没有.
我会说C++进行了更改以使类更容易使用(记住,类和结构在C++中基本上是相同的;它们只在默认可见性方面不同),并且C没有效仿,因为这会破坏大量现有的C代码.