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. k8s入坑之路(5)kube-apiserver详解

    API Server kube-apiserver 是 Kubernetes 最重要的核心组件之一,主要提供以下的功能 提供集群管理的 REST API 接口,包括认证授权.数据校验以及集群状态变更等 ...

  2. let that = this用法解析

    这种情况就是在一个代码片段里this有可能代表不同的对象,而编码者希望this代表最初的对象

  3. js实现一个小游戏(飞翔的jj)

    js实现一个小游戏(飞翔的jj) 源代码+素材图片在我的仓库 <!DOCTYPE html> <html lang="en"> <head> & ...

  4. 学习JS的第二天

    一.数据类型间的转换 主要:数字与字符串之间的转换 1.隐式转换 // console.log(1==true);[] 字符串与数字相加,其结果就是字符串  类似于字符串拼接 concole.log( ...

  5. vue中axios的post和get请求示例

    POST请求 methods: { isclick() { if (this.account == "" || this.pwd == "") { this.$ ...

  6. 博主日常工作中使用的shell脚本分享

    前言: 今天给大家分享一篇在我工作中常用的一个shell脚本,里面有一些我们常用到的shell操作.该脚本用于本地电脑和服务器交互上,实现以下功能: 自动拉取自己个人电脑上的源码到服务器上yocto包 ...

  7. 菜鸡的Java笔记 开发支持类库

    开发支持类库 SupportClassLibrary        观察者设计模式的支持类库                    content (内容)        什么是观察者设计模式呢?   ...

  8. Linux下编译tinyxml生成动态库

    首先去到sourceforge下载tinyxml的源码,https://sourceforge.net/projects/tinyxml/?source=dlp,最新版本是2.6.2. 将下载成功的t ...

  9. SpringCloud升级之路2020.0.x版-40. spock 单元测试封装的 WebClient(上)

    本系列代码地址:https://github.com/JoJoTec/spring-cloud-parent 我们来测试下前面封装好的 WebClient,这里开始,我们使用 spock 编写 gro ...

  10. .NET 百万级 大数据插入、更新 ,支持多种数据库

    功能介绍  (需要版本5.0.44) 大数据操作ORM性能瓶颈在实体转换上面,并且不能使用常规的Sql去实现 当列越多转换越慢,SqlSugar将转换性能做到极致,并且采用数据库最佳API 操作数据库 ...