zoukankan      html  css  js  c++  java
  • C++编译错误cannot have cv-qualifier

    C++编译错误cannot have cv-qualifier

    C++CVconstvolatile两个keyword。有两种情况不能使用CV限定。

    一、非成员函数不能含有CV限定,即constvolatile限定

    #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 限定符有两个:const volatile,这儿指const

    二、静态成员函数不能有CV限定,即constvolatile限定。

    头文件static_cpp.h

    #ifndef __STATIC_H

    #define __STATIC_H

    class CStatic

    {

        private:

            static int static_value;

        public:

            static int get_static_value() const;

    };

    #endif

    源文件staitc_cpp.cpp

    #include"static_cpp.h"

    intCStatic::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;

               return0;

    }

    编译会出现错误,意思是说:静态成员函数,不能有CV限定符,在C++CV限定符指constvolatile,这儿指const

  • 相关阅读:
    switch选择结构
    变量与数据类型
    if选择结构
    NewSQL数据库VoltDB特性简介
    关系代数的并行计算
    【伯乐在线】程序员一定要投资的那些事
    Spark on Yarn
    六星经典CSAPP笔记(1)计算机系统巡游
    程序员的“机械同感”
    Impala中的代码生成技术
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4079325.html
Copyright © 2011-2022 走看看