C++编程常见错误:cannot have cv-qualifier
来源:互联网 发布:南工院网络缴费平台 编辑:程序博客网 时间:2024/05/17 04:02
转自http://blog.163.com/xychenbaihu@yeah/blog/static/132229655201149281131/,作者:无影
1、cannot have cv-qualifier
不能有CV限定符,在C++中CV限定符指const和volatile。
a、在C++中,普通函数(非类的成员函数)不能有CV限定,即const和volatile限定。
即非类的成员行数,用const进行修饰:
int test() const //这是不对的,普通函数(非成员函数不能有CV约束){ //实现}
b、在C++中,静态成员函数(static成员函数)不能有CV限定,即const和volatile限定。
即类的静态成员函数,也不能有CV约束:
class Test{public: static int test_fun() const; //这个是不允许的。}
2、undefined reference to `vtable for ...'
产生问题的原因是::
基类中声明了virual 方法(不是纯虚方法),但是没有实现。在子类中实现了,当子类创建对象时,就出现这个问题。
class Base{public: virtual int run();};class Test:public Base //必须实现run才可以{public: Test() { }};
在Test中必须实现run,否则Test不能创建对象,创建对象,编译时会报 undefined reference to `vtable for ...' 这种错误。
如果是“纯虚函数”,即 virtual int run() = 0;编译时会报" because the following virtual functions are pure within 'Test' "
如果在基类中实现了虚函数,或者在子类中实现纯虚函数或虚函数,就不会报错。
包含有虚函数的类,是不能创建对象的。
3、在C++中,const成员变量也不能在类定义处初始化,只能通过构造函数初始化列表进行,并且必须有构造函数。
例如:
class Test{private: const int a;public: Test() { a = 0; //错误的 }};
在编译时,会报"uninitialized member 'Test::a' with 'const' type 'const int'"错误
在C++中,const成员变量不能在类定义处初始化,只能通过构造函数初始化列表进行,并且必须有构造函数。
Test():a(0){}
- C++编程常见错误:cannot have cv-qualifier
- C++编程常见错误:cannot have cv-qualifier等
- C++编程常见错误—cannot have cv-qualifier//不能有CV限定
- C++编译错误cannot have cv-qualifier
- C++编程常见错误—cannot have cv-qualifier//不能有CV限定,在C++中CV指const和volatile—1、非成员函数不能有CV限定,2、静态成员函数不能有CV限定
- non-member function cannot have cv-qualifier
- c++ error: cannot have cv-qualifier
- C++ Programming Error/Warning Analysis (1) cannot have cv-qualifier
- C++ error:static member function cannot have cv-qualifier
- CV-qualifier
- [BCB]E2089 Identifier 'ReadPragram' cannot have a type qualifier
- c编程常见错误
- 原创:常见C编程错误
- c/c++常见编程错误
- maven错误:dependency cannot have character [children]
- WCF分布式开发常见错误解决(7):System.InvalidOperationException,Cannot have two operations in the same contract
- c语言编程的常见错误
- C语言编程中常见的错误
- 类似hibernate的JDBC(java反射--dao层封转,减少代码书写)
- Android中的ImageView的getDrawableCache获取背景图片的时候注意的问题
- RHEL系统以FTP服务器搭建yum源
- UI基础UIWindow、UIView
- php solr配置mmseg4j分词(widows和Linux都可以,注意地址的配置就好)
- C++编程常见错误:cannot have cv-qualifier
- 代码中坏味道和对应重构方法——摘自《重构,改善既有代码的设计》
- ABAP增强实施-SMOD增强点定位
- 波特词干算法
- 常见面试之机器学习算法思想简单梳理
- asp.net 多行文本框输入长度限制
- 泛型
- 每天一个linux命令:rm (remove)
- 关于python模块自动安装(setuptools)