C语言中,当用指针传递首地址时,可以采用如下形式来解决:
例如:
#include<iostream>
using namespace std
class Student
{
public:
int num;
char nam[10];
float score;
}
Student *chaxun(Student *head)
{
...
另head指向该类的对象的首地址;
然后return head;
}
int main()
{ Student *head=NULL;
调用查询函数:
head=chaxun(head);
...
return 0;
}
此外,还有一种方法,就是用全局变量的方法!
可以在main函数和类的外面定义:Student *head=new Student;注意:这个定义必须要在类定义完以后才能写!