【发布时间】:2016-06-12 19:39:09
【问题描述】:
C++:如下所示的代码和同时在函数声明和定义中省略关键字struct 之间有什么区别——代码似乎以两种方式工作?
#include <iostream>
#include <string>
struct student{
int age;
int number;
};
void printme( struct student m[]); // if 'struct' is omitted the code works as fine
int main()
{
student s[3];
s[0].age = 10;
s[0].number = 333;
printme(s);
return 0;
}
void printme( struct student m[]){
printf("George age and number: %d, %d \n", m[0].age, m[0].number);
}
【问题讨论】:
-
在 C++ 中,没有区别。
-
它主要是向后兼容 c - 两个选项是相同的。
-
实际上没有this work fine?我不明白你的问题。
-
将关键字
struct更改为class,您就会明白为什么会这样了。 C++ Does Not Have Structs -
@πάνταῥεῖ OP 询问为什么它在函数声明中没有
struct关键字起作用。
标签: c++ function struct parameters