错误如下:
d:\My Documents\Visual Studio Projects\563\256\200431046.cpp(99): error C2440: “初始化” : 无法从“const char *”转换为“CLeapYear”
我的程序如下,不知道怎么改了.其他地方都改了就是这样改不了.实在是想不出来,请教各位高手了.
#include <iostream>
#include <string.h>
using namespace std;
struct Syear
{
int start,end;
};
//10
class CLeapYear
{
private:
Syear time;
int r_year;
int *p_leap_year;
int *p_time_name;
static int total_year_object;
static int no_of_leap_year;
public://20
CLeapYear(const Syear &r_time_val,char time_name[]);
int setyear();
bool isLeap();
int findLeapYear();
void print();
~CLeapYear()
{
cout<<"destructing leap_year"<<this->p_leap_year<<endl;
delete p_leap_year;
delete p_time_name;//30
}
};
CLeapYear::CLeapYear(const Syear &r_time_val,char time_name[])
{
cout<<"Constructor with 2 parameters is called"<<endl;
time=r_time_val;
p_time_name=new int[strlen(time_name)+1];
if(time_name==NULL)
exit(1);//40
}
int CLeapYear::setyear()
{
char ch;
ch=cin.get();
cout<<"请选择:输入1,判断将要输入的某个年份是否闰年;输入2,输入起始年份列出期间的所有闰年.\n";
if(ch==1)
cout<<"请输入一个要判断的年份";
cin>>r_year;//50
if(ch==2)
cout<<"请输入起始年份";
cin>>time.start>>time.end;
}
bool CLeapYear::isLeap()
{//60
if(r_year%4 == 0 && r_year%100 != 0)
return true;
if(r_year%400 == 0)
return true;
return false;
}
int CLeapYear::findLeapYear()//70
{
int year;
for(year=time.start;year<=time.end;year++)
{
if((year%4 == 0 && year%100 != 0) || year%400 == 0)
no_of_leap_year++;
p_leap_year=new int[no_of_leap_year+1];
*p_leap_year=year;
return *p_leap_year;//80
}
}
void CLeapYear::print()
{
cout<<"The leap year from"<<time.start<<"to"<<time.end<<"are"<<p_leap_year++;
cout<<endl;
}
//90
int CLeapYear::total_year_object=0;
int CLeapYear::no_of_leap_year=0;
void main()
{
Syear time1={1904,2007},time2={1876,1956};
CLeapYear leapyear1(time1,"first"),leapyear2=(time2,"second");
//100
leapyear1.findLeapYear();
leapyear1.print();
leapyear2.findLeapYear();
leapyear2.print();
}