本人小菜,遇到问题,高手搭救。
出现错误提示:
c:\users\流浪的月光\documents\visual studio 2012\projects\15整数与实数的加减法\15整数与实数的加减法\源.cpp(27): error C2512: “real”: 没有合适的默认构造函数可用
1>c:\users\流浪的月光\documents\visual studio 2012\projects\15整数与实数的加减法\15整数与实数的加减法\源.cpp(32): error C2512: “integer”: 没有合适的默认构造函数可用
#include<iostream>
using namespace std;
class integer
{
public:
integer(int xx,int yy):x(xx),y(yy){}
int pi(){return x+y;}
int mi(){return x-y;}
protected:
int x,y;
}; class real
{
public:
real(double xx,double yy):x(xx),y(yy){}
double pi(){return x+y;}
double mi(){return x-y;}
protected:
double x,y;
}; class intreal:public integer,public real
{
public:
intreal (char cc,int x,int y):integer(x,y)
{
c=cc;
if (c=='+')cout<<integer::pi();else cout<<integer::mi();
}
intreal(char cc,double x,double y):real(x,y)
{
c=cc;
if (c=='+')cout<<real::pi();else cout<<real::mi();
}
protected:
char c;
}; int main()
{
int a,x,y;
double x1,y1;
char c;
while (cin>>c>>a)
{
if (a==0) {cin>>x>>y; intreal YJJ(c,x,y);}
else {cin>>x1>>y1; intreal YJJ(c,x1,y1);}
} }
出现错误提示:
c:\users\流浪的月光\documents\visual studio 2012\projects\15整数与实数的加减法\15整数与实数的加减法\源.cpp(27): error C2512: “real”: 没有合适的默认构造函数可用
1>c:\users\流浪的月光\documents\visual studio 2012\projects\15整数与实数的加减法\15整数与实数的加减法\源.cpp(32): error C2512: “integer”: 没有合适的默认构造函数可用
#include<iostream>
using namespace std;
class integer
{
public:
integer(int xx,int yy):x(xx),y(yy){}
int pi(){return x+y;}
int mi(){return x-y;}
protected:
int x,y;
}; class real
{
public:
real(double xx,double yy):x(xx),y(yy){}
double pi(){return x+y;}
double mi(){return x-y;}
protected:
double x,y;
}; class intreal:public integer,public real
{
public:
intreal (char cc,int x,int y):integer(x,y)
{
c=cc;
if (c=='+')cout<<integer::pi();else cout<<integer::mi();
}
intreal(char cc,double x,double y):real(x,y)
{
c=cc;
if (c=='+')cout<<real::pi();else cout<<real::mi();
}
protected:
char c;
}; int main()
{
int a,x,y;
double x1,y1;
char c;
while (cin>>c>>a)
{
if (a==0) {cin>>x>>y; intreal YJJ(c,x,y);}
else {cin>>x1>>y1; intreal YJJ(c,x1,y1);}
} }