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. kubernetes常见日志采集问题和解决方案分析

    传统日志与kubernetes日志对比 传统服务 目录固定 重启不会丢失 不用关注标准与错误日志输出 容器服务 节点不固定 重启服务会漂移 需要关注标准与错误日志输出 日志文件重启会丢失 日志目录不固 ...

  2. jenkins持续集成Allure生成报表+邮件推送

    本次基于<jenkins 生成HTML报表,邮件推送>的基础上将生成HTML报表修改为Allure生成报表,可以参考官方文档:https://docs.qameta.io/allure/# ...

  3. VIM处理工具与正则表达式

    *本文中/data目录为训练目录 1.在vim中设置TAB缩进为四个字符 打开vim 输入:set tabstop=4 2.复制/etc/rc.d/init.d/functions文件至/tmp/,替 ...

  4. 编译静态库的方式使用spdlog和fmt

    前言 spdlog++库,而且支持header only方式,但header only的使用方式会造成编译时长增加,所以这里简单描述一下,其编译静态库的方式. 又因为spdlog还依赖另一个开源库fm ...

  5. tomcat9启动报错too low setting for -Xss

    在tomcat下部署war包启动时报错,关键错误信息如下: Caused by: java.lang.IllegalStateException: Unable to complete the sca ...

  6. SpringCloud 2020.0.4 系列之 Stream 消息广播 与 消息分组 的实现

    1. 概述 老话说的好:事情太多,做不过来,就先把事情记在本子上,然后理清思路.排好优先级,一件一件的去完成. 言归正传,今天我们来聊一下 SpringCloud 的 Stream 组件,Spring ...

  7. nohup、&、 2>&1详解

    前言 对一个程序员来说,java项目的打包部署也是一项必须掌握的一项技术任务,现我将自己平时在maven下打包以及部署项目总结,希望对有这方面诉求的小伙伴有所帮助! 一.maven项目打包及命令 (1 ...

  8. 尖端之作看逐浪-Zoomla!逐浪CMS python版发布

    免费下载:https://www.z01.com/down/3723.shtml Python是跻身于当代IT世界最流行和代码最高效的编程语言之一. 带着对技术的卓越追求.对客户的承诺.对品质的极致追 ...

  9. difflib模块详解

    1.两个字符串对比 import difflib text1=""" test1 #定义字符串 hellow my name is machanwei! difflib ...

  10. Jenkins快速上手安装

    目录 环境准备 - JDK 安装 1. APT 安装 2. WAR包方式运行 3.Docker 方式运行 Jenkins 是一个独立的开源自动化服务器,可以用来自动化与构建.测试.交付或部署软件相关的 ...