错误处理1: D:\a1-C++\C++作业\第五次1.cpp undefined reference to `vtable for Shape'
在编译程序的时候遇到此误,在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'的更多相关文章
- Qt - 错误总结 - 在自定义类头文件中添加Q_OBJECT 编译时报错(undefined reference to ‘vtable for xxThread)
错误提示:在添加的QThread子类头文件添加Q_OBJECT时,编译程序,出现"undefined reference to 'vtable for xxThread'"错误提示 ...
- Qt错误:类中使用Q_OBJECT宏导致undefined reference to vtable for "xxx::xxx"错误的原因和解决方法
在进行Qt编程的时候,有时候会将类的定义和实现都写在源文件中,如果同时在该类中使用信号/槽,那么可能就会遇到 undefined reference to vtable for "xxx:: ...
- Qt的“undefined reference to `vtable for”错误解决(手动解决,加深理解)
使用QT编程时,当用户自定义了一个类,只要类中使用了信号或槽. Code::Blocks编译就会报错(undefined reference to `vtable for). Google上有很多这个 ...
- [ c++] cmake 编译时 undefined reference to `std::cout' 错误的解决方案
cmake .. 和 make 之后,出现如下错误 Linking CXX executable ../../../bin/ModuleTest CMakeFiles/ModuleTest.dir/ ...
- 解决undefined reference to `__poll_chk@GLIBC_2.16' 错误
出现这个错误,是系统的glibc版本太低了,需要更新 到http://ftp.gnu.org/gnu/glibc/下载新版本的glibc,也不用太高,我选择glibc-2.20.tar.gz 解压 ...
- Android APP使用NDK编译后的ffmpeg库出现undefined reference to 'posix_memalign'错误
在android程序中使用NDK编译后的ffmpeg库的时候出现了如下错误: jni/libs/libavutil.a(mem.o): in function av_malloc:libavutil/ ...
- 解决qt程序的链接阶段出现 undefined reference 错误
错误的原因是我使用到了 QT Widgets 模块中的东西,但是makefile的链接的参数中没有 widgets.其实官网上提到了这个: http://doc.qt.io/qt-5/qtwidget ...
- 错误 undefined reference to __cxa_guard_acquire/release
用gcc编译 c++ 程序时,出现错误 undefined reference to __cxa_guard_acquire linker error, 但是用icc可以正常编译, 问题出在stati ...
- 关于“undefined reference to”错误
哪些问题可能产生undefined reference to错误? 1.没用生成目标文件 比如说hello.o文件,由于名字写错.路径不对.Makefile缺少. 2.没用添加相应的库文件.so/dl ...
随机推荐
- 关于 centos 7系统,iptables透明网桥实现【转载请注明】
首先建立网桥:(使用bridge) 示例 桥接eth0 与 eth1 网口 /sbin/modprobe bridge /usr/sbin/brctl addbr br0 /sbin/ifup ...
- effective c++ 思维导图
历时两个多月的时间,终于把effective c++又复习了一遍,比较慢,看的是英文版,之前看的时候做过一些笔记,但不够详细,这次笔者是从头到尾的翻译了一遍,加了一些标题,先记录到word里面,然后发 ...
- easyUI中datagrid的使用
easyUI中的datagrid数据表格经常被用到,结合项目中的使用情况,总结一下datagrid使用中需要注意的一些问题.使用datagrid展示数据,需要在html.css.js中都要编写代码,h ...
- myeclipse离线安装PyDev
MyEclipse装好了,用来开发java web的,一直可以用,前几天用python写爬虫,也是在myeclipse下,离线安装的包.打开后配置了一下就可以了. 这里用的是PyDev2.8.2 ...
- express4.x的使用
①.安装 npm install -g express ②.创建应用 express [目录] 会在目录下生成 node_modules, 存放所有的项目依赖库.(每个项目管理自己的依赖,与Ma ...
- C#控制台程序使用Log4net日志组件
1.Log4net一般都不陌生,但是在配置上不同类型的项目又不相同的地方比如C#控制台程序和C# MVCWeb项目,拿控制台项目为例 项目源码在文章底部 2.首先创建一个控制台程序,引入Log4n ...
- IDEA 安装scala插件
安装scala插件一般有两种方式,在IDEA里面下载或者手动安装 手动安装 首先是下载需要的插件包,官网下载实在太慢,这里提供我下载好的文件,会按时更新成最新版 https://pan.baidu.c ...
- DOM4J案例详解(添加 ,查询 ,删除 ,保存)
先看一下XML文档 <?xml version="1.0" encoding="gb2312"?> <exam> <student ...
- 每天一道Java题[1]
问题:char[]与String相比,有什么优胜的地方? 回答: 针对安全保密高的信息,char[]比String做得更好.因为String是不可变得,即使你修改原先的变量,实际上也是在内存中新建一个 ...
- 仿中关村win8频道(win8.zol.com.cn)下的tab效果
最近觉得中关村win8频道下的那个Tab效果很好看. 一时兴起就自己做了一个.觉得还蛮不错的,特地来给大家分享一下.以下是相关的HTML页面写法: <div class="popula ...