小编Bla*_*OmN的帖子

C++问题:无法分配抽象类型的对象,但为什么呢?

这是我的C++程序的一些类.

ElementTerrain.h:

#ifndef ELEMENTTERRAIN_H_
#define ELEMENTTERRAIN_H_

#include <iostream>
#include <string>

using namespace std;

class ElementTerrain {
public:
    virtual ~ElementTerrain(){}
    virtual string getElement() const = 0;
    virtual string getType() const = 0;
    virtual int getStock() const = 0;
};

#endif /* ELEMENTTERRAIN_H_ */
Run Code Online (Sandbox Code Playgroud)

Mine.h:

#ifndef MINE_H_
#define MINE_H_

#include "ElementTerrain.h"

using namespace std;

class Mine : public ElementTerrain{
public:
    Mine();
    Mine(bool, bool, int);
    Mine(const Mine &);
    virtual ~Mine();

    string getElement(){
            return "Mine";
        }

    string getType(){
        if(this->ur == true){
            return "UR";}
        if(this->plu …
Run Code Online (Sandbox Code Playgroud)

c++ polymorphism class object abstract

2
推荐指数
1
解决办法
1881
查看次数

标签 统计

abstract ×1

c++ ×1

class ×1

object ×1

polymorphism ×1