模板函数不能是虚函数,原因如下:
 
首先呢,模板函数并不是函数,他需要特定的类型去实例化成为函数。你定义一个函数模板,是不生成任何函数的,只有当你用代码去调用它时,才会根据你的类型去实例化成为特定的函数。

而virtual函数是要写入虚函数表的,是必须要存在的。你可能会想到纯虚函数,纯虚函数只是表明这个函数还未实现,但是已经在父类的虚表里存在了。

因此,模板函数是不能声明为virtual的。

 
静态函数不能是虚函数,原因如下:
 
设计方面的原因:
虚函数是为了实现运行期函数和对象(类的实例)的动态绑定,通过对象的指针或引用访问被指向的对象,只要有继承关系,被访问的对象的实际类型可以和指针或引用指向的类型不同。
如果没有对象,那么这种多态就没有意义,因为根本不存在需要在运行期确定对象类型的必要。
所以只从属于类而不和具体对象相关的静态成员函数作为虚函数是没有意义的,因此语言禁止这么做。

error: templates may not be ‘virtual’的更多相关文章

  1. MDK 虚拟串口 *** error 30: undefined name of virtual register

    概念说明 查看已有的虚拟寄存器 输入指令: dir vtreg 可以看到没有要配置的虚拟寄存器SxIN和SxOUT,通过查询手册可以看到所有的虚拟寄存器类型: 说明不支持.

  2. [Windows Azure] Virtual Machine and Cloud Service Sizes for Windows Azure

    Virtual machine size CPU cores Memory OS disk space–cloud services OS disk space–virtual machines Ma ...

  3. JVM Specification 9th Edition (3) Chapter 2. The Structure of the Java Virtual Machine

    Chapter 2. The Structure of the Java Virtual Machine 内容列表 2.1. The class File Format (class文件的格式) 2. ...

  4. ORA-01733: virtual column not allowed here

    基表: hr.tt  scott.tt  视图1: 基于 hr.tt  union all  scott.tt ---> scott.ttt  视图2: 基于 视图1->scott.ttt ...

  5. mac下php开发环境搭建+CI框架使用

    一.启动apache: apachectl start 停止: apachectl stop 配置文件: vi /etc/apache2/httpd.conf 一.修改端口 因为80端口不想被占用,8 ...

  6. window7配置python3.3 + django + apache24 + mod_wsgi

    window7安装配置python3.3 + django + apache24 + mod_wsgi 1.下载版本的时候要对应 2.apache24 别放系统盘, 不然权限很麻烦 3.django ...

  7. modern-cpp-features

    C++17/14/11 Overview Many of these descriptions and examples come from various resources (see Acknow ...

  8. 运维之利器--Ansible

    一.简介 Ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)的优点,实现了批量系统配置.批量程序部署. ...

  9. elasticsearch7.6 安装 并且开启外网访问,真的好累。

    下载 下载页面 https://www.elastic.co/cn/downloads/elasticsearch wget https://artifacts.elastic.co/download ...

随机推荐

  1. bootstrap之鼠标操作

    TouchLongClick package io.appium.android.bootstrap.handler; import android.os.SystemClock; import co ...

  2. Windows App开发之集合控件与数据绑定

    为ListView和GridView加入数据 ListView採用垂直堆叠得方式显示数据.而GridView则採用水平堆叠得方式. 长相的话嘛,它们都几乎相同. <Grid Name=" ...

  3. JavaScript+Json写的二级联动

    省市区的联动,相当常见 我就不写这么大数据的了,先写个简单的试一试 <!DOCTYPE html> <html> <head> <title></ ...

  4. babylon使用3dsmax导出的obj文件时模型偏暗

    将模型的material的diffuseTexture设置为null即可

  5. Apache JServ Protocol

    ajp_百度百科 https://baike.baidu.com/item/ajp/1187933 AJP(Apache JServ Protocol)是定向包协议.因为性能原因,使用二进制格式来传输 ...

  6. Uninstall Tool3.5.3

    2.卸载所有和MySQL相关的程序,有好几个,注意,一定要删除与MySQL相关的所有的数据,不能用MySQL自带的卸载,我是用Uninstall Tool3.5.3,在卸载程序界面,右键选择与MySQ ...

  7. spring boot 使用redis 及redis工具类

    1-添加maven依赖 2-添加redis配置 3-工具类 1-添加maven依赖 实际上是封装了jedis <!-- redis 依赖--> <dependency> < ...

  8. [转]FPGA入门——basys2开发板的伪随机gold码的生成

    本文原创,转载请注明出处:http://www.cnblogs.com/risten/p/4166169.html 1.系统原理 通过频率控制字选择相位步进,产生访问ROM的地址,进而控制DAC的输出 ...

  9. python string写入二进制文件——直接wb形式open file,再write string即可

    4 down vote accepted You misunderstood what \xhh does in Python strings. Using \x notation in Python ...

  10. 关于Spring Security的笔记

    1.web.xml配置文件 加载Spring Security,将DelegatingFilterProxy配置在DispatcherServlet之前. <filter> <fil ...