In C++, a static member function of a class cannot be virtual.

  For example, below program gives compilation error.

 1 #include<iostream>
2 using namespace std;
3
4 class Test
5 {
6 public:
7 // Error: Virtual member functions cannot be static
8 virtual static void fun()
9 {
10 }
11 };

  

  Also, static member function cannot be const and volatile.

  Following code also fails in compilation.

 1 #include<iostream>
2
3 using namespace std;
4
5 class Test
6 {
7 public:
8 // Error: Static member function cannot be const
9 static void fun() const
10 {
11 }
12 };

  Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

  转载请注明:http://www.cnblogs.com/iloveyouforever/

  2013-11-26  20:31:21

Can static functions be virtual in C++?的更多相关文章

  1. extern static const abstract virtual

    extern static const abstract virtual const const.常量,初始化过后值不能再变化的变量.

  2. [Training Video - 3] [Groovy in Detail] Non-static and Static functions, initializing log inside class

    log.info "starting" // we use class to create objects of a class Planet p1 = new Planet() ...

  3. Shadowing of static functions in Java

    class A { static void fun() { System.out.println("A.fun()"); } } class B extends A { stati ...

  4. objective-c: Functions and static keyword

    Functions function is a concept for C programming language, objective-c is entirely relies on C. To ...

  5. static 关键字

    static对象如果出现在类中,那么该对象即使从未被使用到,它也会被构造以及析构.而函数中的static对象,如果该函数从未被调用,这个对象也就绝不会诞生,但是在函数每次被调用时检查对象是否需要诞生. ...

  6. C++对象模型——指向Member Function的指针 (Pointer-to-Member Functions)(第四章)

    4.4 指向Member Function的指针 (Pointer-to-Member Functions) 取一个nonstatic data member的地址,得到的结果是该member在 cl ...

  7. Delphi之静态方法,虚方法virtual,动态dynamic,抽象abstract,消息

    Delphi之静态方法,虚方法virtual,动态dynamic,抽象abstract,消息 http://www.cnblogs.com/zhwx/archive/2012/08/28/266055 ...

  8. (C/C++ interview) Static 详解

    C Static http://stackoverflow.com/questions/572547/what-does-static-mean-in-a-c-program Static could ...

  9. virtual (C# Reference)

    https://msdn.microsoft.com/en-us/library/9fkccyh4.aspx The virtual keyword is used to modify a metho ...

随机推荐

  1. linux 虚拟网络设备的使用

    1. linux 常见虚拟网络设备分类 常见虚拟网络设备有:bridge, tun/tap, veth-pairs, macvlan, macvtap等.有一篇博文写的挺好的,图文并茂:虚拟网络设备, ...

  2. C++ 内存四区 理解总结

    内存模型图(4G) 整体简单说明 32位CPU可寻址4G线性空间,每个进程都有各自独立的4G逻辑地址,其中 03G是用户空间**,**34G是内核空间即3G用户空间和1G内核空间,不同进程相同的逻辑地 ...

  3. loadRunner运行场景时,事务数为0或是只显示添加的事务的数

    脚本编辑好后,不要着急到controller去执行,注意查看Run-time Settings(运行是设置)-->General(常规)-->Miscellaneous(其他)中查看Aut ...

  4. SVGO: Node.js 开发的 SVG 矢量图优化工具(svg压缩工具)

    SVG图片压缩 这是个通过借助npm包的一种方式去压缩svg的图片,由于阿里的图库自己创建的图标有大小的限制,当我们想要自己用自己的图标的时候就可以使用这种方式去完成对svg的图片压缩. 1.下载no ...

  5. Go语言核心36讲(Go语言实战与应用六)--学习笔记

    28 | 条件变量sync.Cond (下) 问题 1:条件变量的Wait方法做了什么? 在了解了条件变量的使用方式之后,你可能会有这么几个疑问. 1.为什么先要锁定条件变量基于的互斥锁,才能调用它的 ...

  6. jenkins安装与配置---window,mis包直接安装

    https://my.oschina.net/aibinxiao/blog/1457218 Jenkins在Windows下的安装与配置   已经在https://jenkins.io/下载好了Win ...

  7. 【linux系统】命令学习(二)文件处理命令

    查看帮助 1.--help     例如:ls --help  会有中文 2.man       例如:man ls   都是英文 进入手册的界面 空格键:向下翻页 回车:一行一行翻页 B:向前翻页 ...

  8. 网站每日UV数据指标去重统计

    package com.iexecloud.cloud.casemanager;import redis.clients.jedis.Jedis;import java.text.SimpleDate ...

  9. 由于vue的for循环id并不严谨,提高id严谨性

    如果后台没有传入id,我们拿到的数据没有id修改等操作不方便,如何拿到id呢 https://github.com/dylang/shortid 提供唯一id 插件的引入和使用: <templa ...

  10. 洛谷 P6672 - [清华集训2016] 你的生命已如风中残烛(组合数学)

    洛谷题面传送门 题解里一堆密密麻麻的 Raney 引理--蒟蒻表示看不懂,因此决定写一篇题解提供一个像我这样的蒟蒻能理解的思路,或者说,理解方式. 首先我们考虑什么样的牌堆顺序符合条件.显然,在摸牌任 ...