C + + compilation error cannot has Cv-qualifier

Source: Internet
Author: User

C + + compilation error cannot has cv-qualifier

in the C + + in CV means Const and the volatile two x keyword. There are two cases where you cannot use CV -qualification.

a non-member function cannot contain CV qualification, i.e. Const and the volatile Limited

#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;

}

compilation generates an error, meaning that a non-member function cannot have CV Qualifier, CV There are two qualifiers: Const and the volatile , here refers to Const .

second, static member functions cannot have CV qualification, i.e. Const and the volatile Limited.

header File static_cpp.h

#ifndef __static_h

#define __static_h

Class CStatic

{

Private:

static int static_value;

Public:

static int get_static_value () const;

};

#endif

source File staitc_cpp.cpp

#include "Static_cpp.h"

Intcstatic::get_static_value () const

{

return static_value;

}

in the main.cpp in

#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;

}

compile error, meaning: Static member function, cannot have CV Qualifier, in C + + in CV qualifier refers to Const and the volatile , here refers to Const .

C + + compilation error cannot has Cv-qualifier

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.