Can static functions be virtual in C++?
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++?的更多相关文章
- extern static const abstract virtual
extern static const abstract virtual const const.常量,初始化过后值不能再变化的变量.
- [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() ...
- Shadowing of static functions in Java
class A { static void fun() { System.out.println("A.fun()"); } } class B extends A { stati ...
- objective-c: Functions and static keyword
Functions function is a concept for C programming language, objective-c is entirely relies on C. To ...
- static 关键字
static对象如果出现在类中,那么该对象即使从未被使用到,它也会被构造以及析构.而函数中的static对象,如果该函数从未被调用,这个对象也就绝不会诞生,但是在函数每次被调用时检查对象是否需要诞生. ...
- C++对象模型——指向Member Function的指针 (Pointer-to-Member Functions)(第四章)
4.4 指向Member Function的指针 (Pointer-to-Member Functions) 取一个nonstatic data member的地址,得到的结果是该member在 cl ...
- Delphi之静态方法,虚方法virtual,动态dynamic,抽象abstract,消息
Delphi之静态方法,虚方法virtual,动态dynamic,抽象abstract,消息 http://www.cnblogs.com/zhwx/archive/2012/08/28/266055 ...
- (C/C++ interview) Static 详解
C Static http://stackoverflow.com/questions/572547/what-does-static-mean-in-a-c-program Static could ...
- virtual (C# Reference)
https://msdn.microsoft.com/en-us/library/9fkccyh4.aspx The virtual keyword is used to modify a metho ...
随机推荐
- 记录一次因subprocess PIPE 引起的线上故障
sence:python中使用subprocess.Popen(cmd, stdout=sys.STDOUT, stderr=sys.STDERR, shell=True) ,stdout, stde ...
- 记一次,因表变量导致SQL执行效率变慢
场景 最近工作中,发现某同步JOB在执行中经常抛出SQL执行超时的问题,查看日志发现每次SQL执行的时间都是线性增长的,循环执行50次以后执行时间甚至超过了5分钟 JOB执行流程分析 首先,对于JO ...
- Mysql教程:(五)多表查询
多表查询 select name,student.class,student.number,maths,chinese,english from student,score where student ...
- Java之JNDI注入
Java之JNDI注入 About JNDI 0x01 简介 JNDI(Java Naming and Directory Interface)是SUN公司提供的一种标准的Java命名系统接口,JND ...
- Linux内核内存检测工具KASAN
KASAN 是 Kernel Address Sanitizer 的缩写,它是一个动态检测内存错误的工具,主要功能是检查内存越界访问和使用已释放的内存等问题.KASAN 集成在 Linux 内核中,随 ...
- 3组-Alpha冲刺-2/6
一.基本情况 队名:发际线和我作队 组长博客:链接 小组人数:10 二.冲刺概况汇报 黄新成(组长) 过去两天完成了哪些任务 文字描述 在校内外进行了数据采集,采集了多场景的数据,并进行了帧分割. 展 ...
- [loj6033]棋盘游戏
将棋盘黑白染色,即构成一张二分图 将状态用一张二分图$G$和一个点$x\in V$描述(分别为仍未被经过的点的导出子图和当前棋子所在位置),并称将要移动棋子的一方为先手 结论:先手必胜当且仅当$x$一 ...
- [luogu3706]硬币游戏
(可以参考洛谷4548,推导过程较为省略) 定义$g_{i}$表示随机$i$次后未出现给定字符串的概率,$f_{k,i}$表示随机$i$次后恰好出现$s_{k}$(指第$k$个字符串)的概率,设两者的 ...
- 描述高频题之队列&栈
栈和队列 全文概览 基础知识 栈 栈是一种先进后出的数据结构.这里有一个非常典型的例子,就是堆叠盘子.我们在放盘子的时候,只能从下往上一个一个的放:在取的时候,只能从上往下一个一个取,不能从中间随意取 ...
- 如何在 ShardingSphere 中开发自己的 DistSQL
在<DistSQL:像数据库一样使用 Apache ShardingSphere>和<SCTL 涅槃重生:投入 RAL 的怀抱>中,已经为大家介绍了 DistSQL 的设计初衷 ...