在编译程序的时候遇到此误,在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. 浩哥解析MyBatis源码(九)——Type类型模块之类型处理器注册器(TypeHandlerRegistry)

    原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/6709157.html 1.回顾 上一篇研究的是类型别名注册器TypeAliasRegist ...

  2. Python中的支持向量机SVM的使用(有实例)

    除了在Matlab中使用PRTools工具箱中的svm算法,Python中一样可以使用支持向量机做分类.因为Python中的sklearn也集成了SVM算法. 一.简要介绍一下sklearn Scik ...

  3. Windows7 x64 编译Dlib库

    最近用到Dlib库,需要先编译. 本文利用 cmake + Sublime Text 2 + MinGW实现编译. 1. 下载dlib源码[dlib18.17]http://pan.baidu.com ...

  4. My First GitHub

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

  5. DIV+CSS 规范命名集合

    一: 命名规范说明: 1).所有的命名最好都小写 2).属性的值一定要用双引号("")括起来,且一定要有值如class="divcss5",id="d ...

  6. IOS对话框UIAlertView

    //修改弹出对话框的样式 alertView.alertViewStyle = UIAlertViewStylePlainTextInput; //根据索引获取指定的某个文本框 [alertView ...

  7. 像写C#一样编写java代码

    JDK8提供了非常多的便捷用法和语法糖,其编码效率几乎接近于C#开发,maven则是java目前为止最赞的jar包管理和build工具,这两部分内容都不算多,就合并到一起了. 愿编写java代码的过程 ...

  8. CentOS下的yum命令

    yum命令是rpm的一款前端工具,可以安装.更新.卸载rpm包,可以从指定服务器下下载rpm包并安装,可以自动解决依赖问题. 语法: yum [options] [command] [package ...

  9. vue视频学习笔记07

    video 7 vue问题:论坛http://bbs.zhinengshe.com------------------------------------------------UI组件别人提供好一堆 ...

  10. jQuery中的选择器(下)

    这一篇主要写过滤选择器和表单选择器 在这里,我不再已表格形式说明(自己太懒了),主要以文字形式说明一下每个选择器的作用描述.  3.过滤选择器 过滤选择器主要是通过特定的过滤规则筛选出所需的DOM元素 ...