【c++】错误提示:[Error] cannot declare variable 'one' to be of abstract type 'triangle'

错误提示:[Error] cannot declare variable 'one' to be of abstract type 'triangle'

img


各位可以帮忙解决一下报错吗,实在是看不出来应该怎么改,感谢!!
源程序如下:


/*设shape类为表示形状的抽象类,

里面有一个成员函数area( )用于求图形面积的函数,

为纯虚函数total( )则是一个通用的函数,

用于求不同形状的图形面积总和

shape类派生三角形类(triangle),矩形类(rectangle), 

并给出具体的求面积函数,

请将程序补充完整*/

//StudybarCommentBegin
//#include<iostream.h>
#include<math.h>
#include<iostream> 
using namespace std;
class shape
{
//StudybarCommentEnd
protected: 
    double x,y;
public:
    shape(){};
    shape(double a, double b)
    {
        x = a;
        y = b;
    }
    double area(){};
    virtual double total() = 0;
};
//StudybarCommentBegin
class rectangle:public shape   //矩形类 
{
private:
    int width,length;
public:
    rectangle(int c=10,int d=5)//:shape(a,b)
       {width=c;length=d;}
    double area()
       {return width*length;}
};

class triangle:public shape  //三角形类 
{
private:
    double n, height;
public:
    triangle(double nn, double h)
    {
        n = nn;
        height = h;
    }
    double area(){return (1/2)*n*height;}
    
};
double total(shape *s[],int n) 
{ 
    double sum=0.0; 
    for(int i=0;i<n;i++)
        sum=sum+s[i]->area();
    return sum; 
}


int main()
{ 
    shape *sp[2] ;
    int x,y;
    cin>>x>>y;
    triangle one(x,y);
    rectangle two;
    sp[0]=&one;
    sp[1]=&two;
    cout<<"the total area is "<<total(sp,2)<<endl;
}
//StudybarCommentEnd

子类必须实现父类声明的纯虚函数
virtual double total() = 0;

#include<math.h>
#include<iostream> 
using namespace std;
class shape
{
//StudybarCommentEnd
protected: 
    double x,y;
public:
    shape(){};
    shape(double a, double b)
    {
        x = a;
        y = b;
    }
    double area(){};
    virtual double total() = 0;
};
//StudybarCommentBegin
class rectangle:public shape   //矩形类 
{
private:
    int width,length;
public:
    rectangle(int c=10,int d=5)//:shape(a,b)
       {width=c;length=d;}
    double area()
       {return width*length;}
    double total(){}
};
 
class triangle:public shape  //三角形类 
{
private:
    double n, height;
public:
    triangle(double nn, double h)
    {
        n = nn;
        height = h;
    }
    double area(){return (1/2)*n*height;}
    double total(){}
    
};
double total(shape *s[],int n) 
{ 
    double sum=0.0; 
    for(int i=0;i<n;i++)
        sum=sum+s[i]->area();
    return sum; 
}
 
 
int main()
{ 
    shape *sp[2] ;
    int x,y;
    cin>>x>>y;
    triangle one(x,y);
    rectangle two;
    sp[0]=&one;
    sp[1]=&two;
    cout<<"the total area is "<<total(sp,2)<<endl;
}

triangle(double nn, double h)
triangle one(x,y);
x和y应该是double类型