| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1001 人关注过本帖
标题:[求助]郁闷阿!这个程序怎么编译不了?
取消只看楼主 加入收藏
fbt045
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-9-20
收藏
 问题点数:0 回复次数:0 
[求助]郁闷阿!这个程序怎么编译不了?

//studenti.h
#ifndef STUDENTI_H_
#define STUDENTI_H_

#include<iostream>
#include<string>
#include<valarray>

class Student:private std::string,private std::valarray<double>
{
private:
typedef std::valarray<double> ArrayDb;
std::ostream & arr_out(std::ostream & os)const;
public:
Student():std::string("Null Student"),ArrayDb() {}
Student(const std::string & s)
:std::string(s),ArrayDb() {}
explicit Student(int n)
:std::string("Nully"),ArrayDb(n) {}
Student(const std::string & s,int n)
:std::string(s),ArrayDb(n) {}
Student(const std::string & s,const ArrayDb & a)
:std::string(s),ArrayDb(a) {}
Student(const char * str,const double * pd,int n)
:std::string(str),ArrayDb(pd,n) {}
~Student() {}
double Average()const;
const std::string & Name()const;
double & operator[](int i);
double operator[](int i)const;
friend std::istream & operator>>(std::istream & is,
Student & stu);
friend std::istream & getline(std::istream & is,
Student & stu);
friend std::ostream & operator<<(std::ostream & os,
const Student & stu);
};

#endif

//student.cpp
#include"studenti.h"
using std::ostream;
using std::endl;
using std::istream;
using std::string;

double Student::Average()const
{
if(ArrayDb::size()>0)
return ArrayDb::sum()/ArrayDb::size();
else
return 0;
}

const string & Student::Name()const
{
return (const string &)*this;
}

double & Student::operator [](int i)
{
return ArrayDb::operator[](i);
}

double Student::operator [](int i)const
{
return ArrayDb::operator[](i);
}

ostream & Student::arr_out(ostream & os)const
{
int i;
int lim=ArrayDb::size();
if(lim>0)
{
for(i=0;i<lim;i++)
{
os<<ArrayDb::operator[](i)<<" ";
if(i%5==4)
os<<endl;
}
if(i%5!=0)
os<<endl;
}
else
os<<" empty array ";
return os;
}

istream & operator>>(istream & is,Student & stu)
{
is>>(string &)stu;
return is;
}

istream & getline(istream & is,Student & stu)
{
getline(is,(string &)stu);
return is;
}

ostream & operator<<(ostream & os,const Student & stu)
{
os<<"Scores for "<<(const string &)stu<<":\n";
stu.arr_out(os);
return os;
}

//usestu.cpp
#include<iostream>
#include"studenti.h"
using std::cin;
using std::cout;
using std::endl;

void set(Student & sa, int n);

const int pupils=3;
const int quizzes=5;

int main()
{
Student ada[pupils]={Student(quizzes),Student(quizzes),Student(quizzes)};
int i;
for(i=0;i<pupils;i++)
set(ada[i],quizzes);
cout<<"\nStudent List:\n";
for(i=0;i<pupils;i++)
cout<<ada[i].Name()<<endl;
cout<<"\nResults:";
for(i=0;i<pupils;i++)
{
cout<<endl<<ada[i];
cout<<"average: "<<ada[i].Average()<<endl;
}
cout<<"Done.\n";
return 0;
}

void set(Student & sa,int n)
{
cout<<"Please enter the student's name: ";
getline(cin,sa);
cout<<"Please enter "<<n<<" quiz scores:\n";
for(int i=0;i<n;i++)
cin>>sa[i];
while(cin.get()!='\n')
continue;
}
这个程序和我前两天求教的一个程序基本类似,只是前面的用的是包含的类继承,这次是用的私有继承,还是完成输入3个学生的各5门功课成绩,求其各自平均分后输出,我在VC++6.0上编译出现如下错误:
Compiling...
use_stui.cpp
d:\vc源程序练习\use_stui\studenti.h(14) : error C2614: 'Student' : illegal member initialization: 'string' is not a base or member
d:\vc源程序练习\use_stui\studenti.h(15) : error C2614: 'Student' : illegal member initialization: 'string' is not a base or member
d:\vc源程序练习\use_stui\studenti.h(17) : error C2614: 'Student' : illegal member initialization: 'string' is not a base or member
d:\vc源程序练习\use_stui\studenti.h(19) : error C2614: 'Student' : illegal member initialization: 'string' is not a base or member
d:\vc源程序练习\use_stui\studenti.h(21) : error C2614: 'Student' : illegal member initialization: 'string' is not a base or member
d:\vc源程序练习\use_stui\studenti.h(23) : error C2614: 'Student' : illegal member initialization: 'string' is not a base or member
Error executing cl.exe.

use_stui.obj - 6 error(s), 0 warning(s)
难道编译器不支持私有继承?请教各位了

搜索更多相关主题的帖子: 编译 
2006-09-20 10:17
快速回复:[求助]郁闷阿!这个程序怎么编译不了?
数据加载中...
 
   



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

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