标题:[求助]指针问题
取消只看楼主
dick_zq007
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2006-12-5
 问题点数:0 回复次数:0 
[求助]指针问题

//建立一个对象数组,内放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




用函数指向数组首元素怎么写啊? 改了好多次都不行
帮忙改下!!!谢谢

搜索更多相关主题的帖子: Student int 指针 score num 
2007-01-07 14:50



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-114729-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.784955 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved