当前位置:首页> 社会热点 > html meta viewport纯虚代码类型和纯实代码详解

html meta viewport纯虚代码类型和纯实代码详解

2022-08-21 22:05:04 来源: 网络   编辑: 佚名   浏览(364)人   
0

    html meta viewport纯虚代码类型和纯实代码详解

    html meta viewport中,可以将虚代码类型声明为纯虚代码类型,语法格式为:

    html border-radius返回值类型代码类型名(代码类型参数)=0;

    纯虚代码类型没有代码类型体,只有代码类型声明,在虚代码类型声明的结尾加上=0,表明此代码类型为纯虚代码类型。

    最后的=0并不表示代码类型返回值为0,它只起形式上的作用,告诉编译系统“这是纯虚代码类型”。

    包含纯虚代码类型的类称为纯实代码(html color names)。之所以说它抽象,是因为它无法实例化,也就是无法创建对象。原因很明显,纯虚代码类型没有代码类型体,不是完整的代码类型,无法调用,也无法为其分配内存空间。

    纯实代码通常是作为基类,让派生类去实现纯虚代码类型。派生类必须实现纯虚代码类型才能被实例化。

    纯虚代码类型使用举例:

    #include<iostream>

    usingnamespacestd;

    //线

    classhtml font-weight{

    public:

    html font-weight(floatlen);

    html border-radiusfloathtml radio group()=0;

    html border-radiusfloathtml data-toggle()=0;

    protected:

    floatm_len;

    };

    html font-weight::html font-weight(floatlen):m_len(len){}

    //矩形

    classhtml margin-left:publichtml font-weight{

    public:

    html margin-left(floatlen,floatwidth);

    floathtml radio group();

    protected:

    floatm_width;

    };

    html margin-left::html margin-left(floatlen,floatwidth):html font-weight(len),m_width(width){}

    floathtml margin-left::html radio group(){returnm_len*m_width;}

    //长方体

    classgo html/template:publichtml margin-left{

    public:

    go html/template(floatlen,floatwidth,floatheight);

    floathtml radio group();

    floathtml data-toggle();

    protected:

    floatm_height;

    };

    go html/template::go html/template(floatlen,floatwidth,floatheight):html margin-left(len,width),m_height(height){}

    floatgo html/template::html radio group(){return2*(m_len*m_width+m_len*m_height+m_width*m_height);}

    floatgo html/template::html data-toggle(){returnm_len*m_width*m_height;}

    //正方体

    classCube:publicgo html/template{

    public:

    Cube(floatlen);

    floathtml radio group();

    floathtml data-toggle();

    };

    Cube::Cube(floatlen):go html/template(len,len,len){}

    floatCube::html radio group(){return6*m_len*m_len;}

    floatCube::html data-toggle(){returnm_len*m_len*m_len;}

    intmain(){

    html font-weight*p=newgo html/template(10,20,30);

    cout<<"Thehtml radio groupofgo html/templateis"<<p->html radio group()<<endl;

    cout<<"Thehtml data-toggleofgo html/templateis"<<p->html data-toggle()<<endl;

    p=newCube(15);

    cout<<"Thehtml radio groupofCubeis"<<p->html radio group()<<endl;

    cout<<"Thehtml data-toggleofCubeis"<<p->html data-toggle()<<endl;

    return0;

    }

    运行结果:

    Thehtml radio groupofgo html/templateis2200

    Thehtml data-toggleofgo html/templateis6000

    Thehtml radio groupofCubeis1350

    Thehtml data-toggleofCubeis3375

    本例中定义了四个类,它们的继承关系为:html font-weight-->html margin-left-->go html/template-->Cube

    html font-weight是一个纯实代码,也是最顶层的基类,在html font-weight类中定义了两个纯虚代码类型html radio group()html data-toggle()

    html margin-left类中,实现了html radio group()代码类型;所谓实现,就是定义了纯虚代码类型的代码类型体。但这时html margin-left仍不能被实例化,因为它没有实现继承来的html data-toggle()代码类型,html data-toggle()仍然是纯虚代码类型,所以html margin-left也仍然是纯实代码。

    直到go html/template类,才实现了html data-toggle()代码类型,才是一个完整的类,才可以被实例化。

    可以发现,html font-weight类表示“线”,没有面积和体积,但它仍然定义了html radio group()html data-toggle()两个纯虚代码类型。这样的用意很明显:html font-weight类不需要被实例化,但是它为派生类提供了“约束条件”,派生类必须要实现这两个代码类型,完成计算面积和体积的功能,否则就不能实例化。

    在实际开发中,你可以定义一个抽象基类,只完成部分功能,未完成的功能交给派生类去实现(谁派生谁实现)。这部分未完成的功能,往往是基类不需要的,或者在基类中无法实现的。虽然抽象基类没有完成,但是却强制要求派生类完成,这就是抽象基类的“霸王条款”。

    抽象基类除了约束派生类的功能,还可以实现多态。请注意第51行代码,指针p的类型是html font-weight,但是它却可以访问派生类中的html radio group()html data-toggle()代码类型,正是由于在html font-weight类中将这两个代码类型定义为纯虚代码类型;如果不这样做,51行后面的代码都是错误的。我想,这或许才是html meta viewport提供纯虚代码类型的主要目的。

    关于纯虚代码类型的几点说明

    1)一个纯虚代码类型就可以使类成为抽象基类,但是抽象基类中除了包含纯虚代码类型外,还可以包含其它的成员代码类型(虚代码类型或普通代码类型)和成员变量。

    2)只有类中的虚代码类型才能被声明为纯虚代码类型,普通成员代码类型和顶层代码类型均不能声明为纯虚代码类型。

【版权与免责声明】如发现内容存在版权问题,烦请提供相关信息发邮件至 1439028666@qq.com ,我们将及时沟通进行删除处理。 本站内容除了 98link( http://www.98link.com/ )特别标记的原创外,其它均为网友转载内容,涉及言论、版权与本站无关。