Jump to content
  • Advertisement
Sign in to follow this  
nlbs

static member function cannot have a cv-qualifier

This topic is 3740 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

It Compiles
static const long& getLifetime() {return lifeTime;}

But it doesn't
static const long& getLifetime() const{return lifeTime;}

Error Shown
error: static member function ‘static const long int& SessionConfig::getLifetime()’ cannot have cv-qualifier
is const (that one on the right hand side) a cv-qualifier ?? what does the term cv-qualifier mean ?? and why it cannot have a cv-qualifier ??

Share this post


Link to post
Share on other sites
Advertisement
cv-qualifier is compiler speak for something marking a function as const (in this case the keyword "const" placed after the method declaration.).

A static member function cannot be marked as const because doing so wouldn't make any sense in the first place. const is used in order to mark which functions can and cannot mutate an instance of the class, such that a const object can't be changed by mutator methods but still allows calls to methods marked as const. If there was no const qualifier on these methods, then the compiler wouldn't allow one to call them on a const instance of the object. Since static methods aren't related to any particular instance of the class and can only access static member variables, there is no reason for a static method to be marked as const and therefore the compiler considers this an error.

Share this post


Link to post
Share on other sites
cv-qualifier is basically a generalized term that refers to the keywords const and volatile.

Visual Studio has a number of "precautions" to prevent users from casting something that is cv-qualified to a void* and back to a regular pointer (thus eliminating the cv-qualification). This seems to be one such barrier.

For more info, check out this blog:
http://learningcppisfun.blogspot.com/2005/07/casting-cv-qualifier-and-function.html

Edit: gah! ninja'd!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!