#include<iostream>
#include<string>
using namespace std;
class CCourse{
protected:
long no;
float credit;
static int total_course;
public:
CCourse(long n,float c)
{
no=n;
credit=c;
total_course++;
}
CCourse(CCourse &a)
{
no=a.no;
credit=a.credit;
}
~CCourse()
{
cout<<"调用CCourse析构函数"<<endl;
}
void print()
{
cout<<"课程号:"<<no<<endl;
cout<<"课程学分:"<<credit<<endl;
}
int getTotalCourse();
friend int getTotalNo(CCourse &);
bool operator<(const CCourse &b);
};
class COOP:public CCourse{
protected:
char *p_openby;
public:
COOP(long n,float c,char *p):CCourse(n,c)
{
p_openby=new char[strlen(p)+1];
strcpy(p_openby,p);
}
COOP(COOP &a)
{
no=a.no;
credit=a.credit;
p_openby=new char[strlen(a.p_openby)+1];
strcpy(this->p_openby,a.p_openby);
}
bool select(const char *p_xh);
void print();
~COOP()
{
cout<<"调用COOP析构函数"<<endl;
delete []p_openby;
}
};
bool COOP::select(const char *p_xh)
{
int r;
char *a="2016";
r=strncmp(p_xh,a,4);
if(r==0)
return true;
else return false;
}
int CCourse::total_course=0;
int getTotalNo(CCourse &a)
{
return a.no;
}
int CCourse::getTotalCourse()
{
return total_course;
}
bool CCourse::operator <(const CCourse &b)
{
if(this->credit<b.credit)
return true;
else return false;
}
void COOP::print()
{
CCourse::print();
cout<<p_openby<<endl;
}
int main()
{
CCourse sub1(12,3.5);
CCourse sub2(sub1);
CCourse sub3(36,5);
sub1.print();
sub2.print();
sub3.print();
cout<<"课程总数:"<<sub3.getTotalCourse()<<endl;
cout<<"课程号:"<<getTotalNo(sub3)<<endl;
if(sub1<sub3)
cout<<"sub1小于sub3"<<endl;
else cout<<"sub1不小于sub3"<<endl;
COOP sub4(2,5,"面向对象程序设计");
COOP sub5(sub4);
sub4.print();
sub5.print();
char *stu[10];
system("pause");
return 0;
}
求解答,C++,error c2512
最新推荐文章于 2024-08-07 23:26:04 发布