Can static functions be virtual in C++?
2024-09-04 00:06:33
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
最新文章
- 限制Xamarin获取图片的大小
- liunx打开指定端口
- ReactiveCocoa中信号的使用
- 根据List中对象的某一属性进行排序
- 常用 CSS 中文字体 Unicode 编码表
- JSF 2.0 hello world example
- THINKPHP 5.0目录结构
- MySQL主从复制的配置
- ArcGIS地图打印那些事
- Java 领域从传统行业向互联网转型你必须知道的事儿
- js优化 前端小白适用
- Hibernate入门(二)——hibernateAPI详解
- Apache与Nginx动静分离
- [转] mongoose学习笔记(超详细)
- Nodejs----单点登录
- vuex 知识点
- collectd+influxdb+grafana
- 使用uwsgi发布项目
- lightoj 1205 数位dp
- Makefile--基本规则(零)