C++编程常见错误—cannot have cv-qualifier//不能有CV限定,在C++中CV指const和volatile—1、非成员函数不能有CV限定,2、静态成员函数不能有CV限定
2013-08-05 15:36
411 查看
http://blog.163.com/xychenbaihu@yeah/blog/static/132229655201132564041489/
情况一、在C++中,非成员函数不能含有CV限定,即const和volatile限定
#include <iostream>
using namespace std;
double getArea() const
{
return 0.0;
}
double getVolume() const
{
return 0.0;
}
int main(int arg,char *argv[])
{
cout << getArea() << endl;
cout << getVolume() << endl;
return 0;
}
编译产生错误:
![](http://img776.ph.126.net/RhBHJt2al7jtdhdB0yofjA==/89227567618629523.jpg)
意思是:
非成员函数不能有cv 限定符,cv 限定符 c++有两个:const 和 volatile,这儿指const 。
情况二、在C++中,静态成员函数不能有CV限定,即const和volatile限定
头文件static_cpp.h
#ifndef __STATIC_H
#define __STATIC_H
class CStatic
{
private:
static int static_value;
public:
static int get_static_value()
const; //当不是static方法时,可以用const进行限定。
};
#endif
源文件staitc_cpp.cpp
#include "static_cpp.h"
int CStatic::get_static_value() const
{
return static_value;
}
在main.cpp中
#include "static_cpp.h"
#include <iostream>
using namespace std;
int CStatic::static_value = 1;
int main(int argc,char *argv[])
{
cout << CStatic::get_static_value()<<endl;
return 0;
}
编译出现的错误:
![](http://img66.ph.126.net/kCggc2gPSiKXfWTPUWAw3g==/837106580739267921.jpg)
意思是:
静态成员函数,不能有CV限定符,在C++中CV限定符指const和volatile,这儿指const。
情况一、在C++中,非成员函数不能含有CV限定,即const和volatile限定
#include <iostream>
using namespace std;
double getArea() const
{
return 0.0;
}
double getVolume() const
{
return 0.0;
}
int main(int arg,char *argv[])
{
cout << getArea() << endl;
cout << getVolume() << endl;
return 0;
}
编译产生错误:
![](http://img776.ph.126.net/RhBHJt2al7jtdhdB0yofjA==/89227567618629523.jpg)
意思是:
非成员函数不能有cv 限定符,cv 限定符 c++有两个:const 和 volatile,这儿指const 。
情况二、在C++中,静态成员函数不能有CV限定,即const和volatile限定
头文件static_cpp.h
#ifndef __STATIC_H
#define __STATIC_H
class CStatic
{
private:
static int static_value;
public:
static int get_static_value()
const; //当不是static方法时,可以用const进行限定。
};
#endif
源文件staitc_cpp.cpp
#include "static_cpp.h"
int CStatic::get_static_value() const
{
return static_value;
}
在main.cpp中
#include "static_cpp.h"
#include <iostream>
using namespace std;
int CStatic::static_value = 1;
int main(int argc,char *argv[])
{
cout << CStatic::get_static_value()<<endl;
return 0;
}
编译出现的错误:
![](http://img66.ph.126.net/kCggc2gPSiKXfWTPUWAw3g==/837106580739267921.jpg)
意思是:
静态成员函数,不能有CV限定符,在C++中CV限定符指const和volatile,这儿指const。
相关文章推荐
- C++编程常见错误—cannot have cv-qualifier//不能有CV限定
- C++编程常见错误:cannot have cv-qualifier等
- C++编程常见错误:cannot have cv-qualifier
- C++编译错误cannot have cv-qualifier
- C++编译错误cannot have cv-qualifier
- C++编译错误cannot have cv-qualifier
- C++里的静态成员函数为何不能用const?
- C++里的静态(static)成员函数(不能用const的原因+static在c++中的第五种含义)
- C++里的静态成员函数(不能用const的原因+static在c++中的第五种含义)
- C++里的静态成员函数不能用const的原因
- C++里的静态成员函数(不能用const的原因+static在c++中的第五种含义)(转)
- C++静态成员函数不能声明为const、volatile、virtual的原因 与 C++的对象模型
- 为什么静态成员函数不能是const
- C++点滴——const/volatile不能用来修饰没有this指针的成员函数
- C++ 静态成员与成员函数链接错误
- C++ Programming Error/Warning Analysis (1) cannot have cv-qualifier
- C++之静态成员函数为什么不能为虚函数
- 静态成员函数为何不能const
- 为什么静态成员函数不能是const