C++编程常见错误:cannot have cv-qualifier等
来源:互联网 发布:博途软件下载 编辑:程序博客网 时间:2024/06/01 11:33
1、cannot have cv-qualifier
不能有CV限定符,在C++中CV限定符指const和volatile。
a、在C++中,普通函数(非类的成员函数)不能有CV限定,即const和volatile限定。
即非类的成员行数,用const进行修饰:
inttest()const //这是不对的,普通函数(非成员函数不能有CV约束)
{
//实现
}
b、在C++中,静态成员函数(static成员函数)不能有CV限定,即const和volatile限定。
即类的静态成员函数,也不能有CV约束:
class Test
{
public:
static int test_fun() const; //这个是不允许的。
}
2、undefinedreference to `vtable for ...'
产生问题的原因是: 基类中声明了virual 方法(不是纯虚方法),但是没有实现。在子类中实现了,当子类创建对象时,就出现这个问题。
class Base
{
public:
virtual int run();
};
class Test:publicBase //必须实现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; //错误的
}
};
在编译时,会报"uninitializedmember 'Test::a' with 'const' type 'const int'"错误。
在C++中,const成员变量不能在类定义处初始化,只能通过构造函数初始化列表进行,并且必须有构造函数。
Test():a(0)
{
}
文章来源:http://blog.163.com/xychenbaihu@yeah/blog/static/132229655201149281131/
- 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语言编程中常见的错误
- [整理]Objective-C与C++的不同和鸭子类型
- android sdk 无法更新问题
- [转载]C++中静态成员数据与静态成员函数小结
- The Beautiful Sentences
- Hibernate
- C++编程常见错误:cannot have cv-qualifier等
- ~/.bashrc, ~/.bash_profile 以及/etc/profile /etc/bashrc 几个文件的区别与相互关系
- mysql句法
- .net zip压缩包装类
- (1)MATLAB 直方图
- FFMPeg代码分析:AVPacket结构体和av_read_frame函数
- Android VNC Server on G1 (PC 远程控制 Android 手
- Activity管理
- cocos2dx android版本移植时的Error format not a string literal and no format arguments解决方案