c++ - 不能将变量“声明为抽象类型”
问题描述
我有一个名为“SHAPE”的基类,它只包含纯虚函数,其中每个方法 = 0。该基类的派生类是 TRIANGLE。它的所有方法都是从基类 SHAPE 派生的。我仔细检查了代码,但我发现代码中没有错误。为什么编译器一直对我大喊我不能声明一个类型为 TRIANGLE 的变量?
形状.h
#ifndef SHAPE_H
#define SHAPE_H
#include "POINT.h"
class SHAPE
{
public:
SHAPE();
~SHAPE();
virtual bool isValid() const = 0;
virtual double getArea() const = 0;
virtual void set_sides() = 0;
virtual POINT operator[](const int index) const = 0;
virtual bool isInside(const POINT& other) const = 0;
};
#endif // SHAPE_H
三角形.h
#ifndef TRIANGLE_H
#define TRIANGLE_H
#include <SHAPE.h>
#include <stdio.h>
#include <iostream>
using namespace std;
class TRIANGLE : public SHAPE
{
public:
TRIANGLE();
~TRIANGLE();
TRIANGLE(const POINT* arr);
TRIANGLE(const POINT& first, const POINT& second, const POINT& third);
bool isValid() const;
double getArea() const;
void set_sides();
bool isInside() const;
POINT operator[](const int index) const;
private:
POINT *points = new POINT[3];
double sides[3];
};
#endif // TRIANGLE_H
主文件
#include <iostream>
#include <stdio.h>
#include "Render.h"
#include "GAME_SYSTEM.h"
#include "POINT.H"
#include "TRIANGLE.h"
#include "QUAD.h"
using namespace std;
Render* Render::RENDER = new Render();// ignore this
int main(int argc, char* argv[])
{
Render* RENDER = Render::getInstance();//ignore this
POINT a(3,3);
POINT b(3,4);
POINT c(4,3);
TRIANGLE bob(a,b,c);//The problem is here
printf("%i", bob[0].get('x'));//print the x value of the first point of triangle bob.
return 0;
}
解决方案
推荐阅读
- matlab - 如何消除点之间的线
- batch-file - 比较批处理文件中相同文件的大小
- javascript - JavaScript - 使用数组或链表更快地计算二叉树的高度
- java - 请求队列和json
- javascript - 新的 Javascript Const 关键字使用
- php - 将节点添加到 XML 变量并保存
- java - WebClient 的 bodyToMono 错误
- javascript - 如何修复 Internet Explorer 中的“SCRIPT424:所需对象:'环境'”
- python - Python Pandas Groupby 添加列除以获取平均值
- python - TensorFlow estimator.DNNClassifier:export_savedmodel 导致“ValueError:Invalid feature”