C++编程常见错误—cannot have cv-qualifier//不能有CV限定
来源:互联网 发布:vasp软件价格 编辑:程序博客网 时间:2024/06/05 09:56
在C++中CV指const和volatile—
1、非成员函数不能有CV限定,友元函数不是类的成员函数声明友元函数不能用const限定。
2、静态成员函数不能有CV限定
情况一、在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;
}
编译产生错误:
意思是:
非成员函数不能有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;
}
编译出现的错误:
意思是:
静态成员函数,不能有CV限定符,在C++中CV限定符指const和volatile,这儿指const。
情况三:#include<iostream>
#include<string>
using namespace std;
class Animal{
public:
friend void showRes(Animal &ref)const;//这行编译器会给错误non-member function ‘void showRes(Animal&)’ cannot have cv-qualifier
friend void showRes(Animal &ref)const;
private:
int age;
string name;
};
void showRes(Animal &ref){
ref.age=15;
ref.name="panda";
cout << ref.age << ref.name << endl;
}
- C++编程常见错误—cannot have cv-qualifier//不能有CV限定
- C++编程常见错误—cannot have cv-qualifier//不能有CV限定,在C++中CV指const和volatile—1、非成员函数不能有CV限定,2、静态成员函数不能有CV限定
- C++编程常见错误:cannot have cv-qualifier
- C++编程常见错误:cannot have cv-qualifier等
- C++编译错误cannot have cv-qualifier
- 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
- C/C++:CV限定的理解
- 10.CV限定符
- CV
- cv
- CV
- CV
- CV
- 7.1.5.1 cv限定符
- Java异常
- HashMap死循环问题分析
- Flexbox——快速布局神器
- hihocoder 1252 Kejin Game dinic网络流
- Mysql中文乱码问题完美解决方案
- C++编程常见错误—cannot have cv-qualifier//不能有CV限定
- 奇异值分解(SVD)详解
- Java基础--List的创建
- H5小动画,分享一下!!
- ZOJ 3777 Problem Arrangement (状压DP)
- 手机微信发语音没有声音
- chart.js + bootstrap +jquery.js 实现的 html5 图表绘制效果
- 图像分割的三类方法
- 12. spring4.1.6+spring mvc4.1.6+spring data jpa1.7.0+maven整合