求解答重载运算符编译为什么不通过
// gg.cpp : Defines the entry point for the console application.//
//#include "stdafx.h"
#include <iostream>
using namespace std;
class Shape
{public:
virtual double area() const {return 0.0;}
virtual double max() const {return 0.0;}
virtual void shapeName() const =0;
};
class Trapezoid;
class circle:public Shape
{
public:
circle(double=0,double=0,double=0);
setcircle(double,double,double);
void Judgement(circle &p);
virtual double area();
virtual void shapeName() const {cout<<"circle:";}
operator + (Trapezoid &t);
operator + (circle &c);
private:
double x;
double y;
double ra;
};
circle::setcircle(double a,double b,double r)
{ x=a;y=b;ra=r;}
circle::circle(double a,double b,double r)
{x=a;y=b;ra=r;}
void circle::Judgement(circle &c)
{if (ra>=0)
cout<<"是个圆"<<endl;
}
circle::operator + (Trapezoid &t)
{ return circle(x+t.getx(),y+t.gety(),ra+t.max());}
double circle::area()
{cout<<"area="<<ra*ra*3.1415<<endl;
return 0;}
class Trapezoid:public circle
{
Trapezoid(double=0,double=0,double=0);
getx();
gety();
virtual double max() const;
void Judgement(Trapezoid &t);
private:
double top;
double bot;
double hig;
};
Trapezoid::getx()
{return top;}
Trapezoid::gety()
{return bot;}
double Trapezoid::max () const
{
double m,n;
m=top>bot?top:bot;
n=hig>m?hig:m;
return n;
}
void Trapezoid::Judgement(Trapezoid &t)
{
if(top>0 && bot>0 && hig>0)
cout<<"是一个梯形!"<<endl;
else
cout<<"不是一个梯形!"<<endl;
}
Trapezoid::Trapezoid(double a,double b,double h)
{top=a;bot=b;hig=h;}
int main(int argc, char* argv[])
{
printf("Hello World!\n");
return 0;
}
错误提示是
--------------------Configuration: gg1 - Win32 Debug--------------------
Compiling...
gg1.cpp
c:\users\me\desktop\gg1.cpp(39) : error C2027: use of undefined type 'Trapezoid'
c:\users\me\desktop\gg1.cpp(14) : see declaration of 'Trapezoid'
c:\users\me\desktop\gg1.cpp(39) : error C2228: left of '.getx' must have class/struct/union type
c:\users\me\desktop\gg1.cpp(39) : error C2027: use of undefined type 'Trapezoid'
c:\users\me\desktop\gg1.cpp(14) : see declaration of 'Trapezoid'
c:\users\me\desktop\gg1.cpp(39) : error C2228: left of '.gety' must have class/struct/union type
c:\users\me\desktop\gg1.cpp(39) : error C2027: use of undefined type 'Trapezoid'
c:\users\me\desktop\gg1.cpp(14) : see declaration of 'Trapezoid'
c:\users\me\desktop\gg1.cpp(39) : error C2228: left of '.max' must have class/struct/union type
执行 cl.exe 时出错.
gg1.exe - 1 error(s), 0 warning(s)