|
//建立一个对象数组,内放5个学生数据,用指针指向首元素,输出第1,3,5个学生的数据
#include <iostream>
using namespace std;
class Student
{ public:
Student(int,int);
private:
int num;
int score;
};
Student::Student(int n,int s):num(n),score(s){}
int main()
{ Student a[5]={
Student(1,70),
Student(2,65),
Student(3,80),
Student(4,90),
Student(5,75)
};
int i;
int *p=&a[];
for(i=0;i<5;i++)
if(i%2==0)
p=p->a[i];
cout<<*p<<endl;
return 0;
}
21 D:\Dev-Cpp\program\cpp3.cpp expected primary-expression before ']' token
24 D:\Dev-Cpp\program\cpp3.cpp `a' is not a type
24 D:\Dev-Cpp\program\cpp3.cpp request for member of non-aggregate type before '[' token
用函数指向数组首元素怎么写啊? 改了好多次都不行
帮忙改下!!!谢谢 |
|