在编译程序的时候遇到此误,在google上查,很多地方都说是因为虚基类里面的虚拟析构函数没有提供实现导致的。但是我的已经提供了实现,也不行。最后发现是其他没有提供实现的虚函数造成的。所以,在一个虚基类里,如果不提供函数的缺省实现,一定要定义成纯虚函数,否则就会造成此问题。

#include <iostream> using namespace std; #define pi 3.14

class Shape{  public:   static double sum;   virtual void show()const; };

double Shape::sum = 0;

class Circle : public Shape{  private:   double r;  public:   Circle(double r1):r(r1){    sum += r * r * pi;   }    void show()const{    cout << "圆:" << endl;    cout << "圆的半径:" << r << endl;    cout << "圆的面积:" << r * r * pi << endl;   } }; class Rectanglez: public Shape{  private:   double x;  public:   Rectanglez(double x1): x(x1){    sum += x * x;   }    void show()const{    cout << "正方形:" << endl;    cout << "正方形的边长:" << x << endl;    cout << "正方形的面积:" << x * x << endl;   } }; class Rectanglec: public Shape{  private:   double x, y;  public:   Rectanglec(double x1, double y1): x(x1), y(y1){    sum += x * y;   }   void show()const{    cout << "长方形:" << endl;    cout << "长方形的长、宽: " << x << y << endl;    cout << "长方形的面积:" << x * y << endl;   } }; int main(){  Shape *p;  char flag = 'Y';  while(toupper(flag) == 'Y'){   int select;   cout << "请选择需要输入的类型:1(圆), 2(正方形), 3(长方形)" << endl;   cin >> select;   switch(select){    case 1:     double r;     cin >> r;     p = new Circle(r);     p->show();     delete p;     break;    case 2:     double x;     cin >> x;     p = new Rectanglez(x);     p->show();     delete p;     break;    case 3:     double x1, y;     cin >> x1 >> y;     p = new Rectanglec(x1, y);     p->show();     delete p;     break;    default:     cout << "输入错误!" << endl;     break;   }   cout << "是否继续输入:N or Y ?" << endl;   cin >> flag;  }  return 0; }

错误处理1: D:\a1-C++\C++作业\第五次1.cpp undefined reference to `vtable for Shape'的更多相关文章

  1. Qt - 错误总结 - 在自定义类头文件中添加Q_OBJECT 编译时报错(undefined reference to ‘vtable for xxThread)

    错误提示:在添加的QThread子类头文件添加Q_OBJECT时,编译程序,出现"undefined reference to 'vtable for xxThread'"错误提示 ...

  2. Qt错误:类中使用Q_OBJECT宏导致undefined reference to vtable for "xxx::xxx"错误的原因和解决方法

    在进行Qt编程的时候,有时候会将类的定义和实现都写在源文件中,如果同时在该类中使用信号/槽,那么可能就会遇到 undefined reference to vtable for "xxx:: ...

  3. Qt的“undefined reference to `vtable for”错误解决(手动解决,加深理解)

    使用QT编程时,当用户自定义了一个类,只要类中使用了信号或槽. Code::Blocks编译就会报错(undefined reference to `vtable for). Google上有很多这个 ...

  4. [ c++] cmake 编译时 undefined reference to `std::cout' 错误的解决方案

    cmake ..  和 make 之后,出现如下错误 Linking CXX executable ../../../bin/ModuleTest CMakeFiles/ModuleTest.dir/ ...

  5. 解决undefined reference to `__poll_chk@GLIBC_2.16' 错误

    出现这个错误,是系统的glibc版本太低了,需要更新 到http://ftp.gnu.org/gnu/glibc/下载新版本的glibc,也不用太高,我选择glibc-2.20.tar.gz   解压 ...

  6. Android APP使用NDK编译后的ffmpeg库出现undefined reference to 'posix_memalign'错误

    在android程序中使用NDK编译后的ffmpeg库的时候出现了如下错误: jni/libs/libavutil.a(mem.o): in function av_malloc:libavutil/ ...

  7. 解决qt程序的链接阶段出现 undefined reference 错误

    错误的原因是我使用到了 QT Widgets 模块中的东西,但是makefile的链接的参数中没有 widgets.其实官网上提到了这个: http://doc.qt.io/qt-5/qtwidget ...

  8. 错误 undefined reference to __cxa_guard_acquire/release

    用gcc编译 c++ 程序时,出现错误 undefined reference to __cxa_guard_acquire linker error, 但是用icc可以正常编译, 问题出在stati ...

  9. 关于“undefined reference to”错误

    哪些问题可能产生undefined reference to错误? 1.没用生成目标文件 比如说hello.o文件,由于名字写错.路径不对.Makefile缺少. 2.没用添加相应的库文件.so/dl ...

随机推荐

  1. jsp之session对象

    jsp之session对象:一:概念session对象可以在应用程序的web页面之间跳转时保存用户的信息,使整个用户会话一直存在,直到关闭浏览器或是销毁session.session的生命周期:20~ ...

  2. Android Weekly Notes Issue #254

    Android Weekly Issue #254 April 23rd, 2017 Android Weekly Issue #254 本期内容包括: 如何用Kotlin写一个Gradle Plug ...

  3. edge animate从入门到放弃

    一.什么是edge animate edge animate这是一款方便网页设计师和前端工程师实现动画交互的一款工具,虽然是adobe出品的,但是属于Flash和H5时代的过渡产物,这一款产品在201 ...

  4. 【openstack N版】——摘除一个计算节点

    1.查看计算节点 #查看所有计算节点 [root@open-control01 ~]# nova service-list+----+------------------+-------------- ...

  5. My First GitHub

    第一次使用github 在https://github.com/注册账号. 登陆之后,首先创建一个仓库(+ new repository),开源(public)的仓库是免费的,私人(private)的 ...

  6. Struts2之Action接收请求参数和拦截器

    技术分析之在Struts2框架中使用Servlet的API        1. 在Action类中也可以获取到Servlet一些常用的API        * 需求:提供JSP的表单页面的数据,在Ac ...

  7. PHP自定义函数

    啊哈

  8. [刷题]Codeforces 785D - Anton and School - 2

    Description As you probably know, Anton goes to school. One of the school subjects that Anton studie ...

  9. Spring AOP的切入点表达式

    在spring Aop中要使用AspectJ的切点表达式语言来定义切点.Spring仅仅支持AspectJ切点指示器的一个子集.下表列出了Spring AOP所支持的AspectJ切点指示器. 在Sp ...

  10. C#单元测试,带你入门

    注:本文示例环境 VS2017 XUnit 2.2.0 单元测试框架 xunit.runner.visualstudio 2.2.0 测试运行工具 Moq 4.7.10 模拟框架 为什么要编写单元测试 ...