c++ – non-member function cannot have cv-qualifier

c++ – non-member function cannot have cv-qualifier

Your desire not to modify t is expressed in const T& t. The ending const specifies that you will not modify any member variable of the class abs belongs to.

Since there is no class where this function belongs to, you get an error.

The const modifier at the end of the function declaration applies to the hidden this parameter for member functions.

As this is a free function, there is no this and that modifier is not needed.

The t parameter already has its own const in the parameter list.

c++ – non-member function cannot have cv-qualifier

The cv-qualifier on a member function specifies that the this pointer is to have indirected type const (or volatile, const volatile) and that therefore the member function can be called on instances with that qualification.

Free functions (and class static functions) dont have a this pointer.

Leave a Reply

Your email address will not be published.