Shouldn't this generate a warning? (const, non-const)

class foo{

   void bar(const long var_name);

};

 

void foo::bar(long var_name){

}

 

Since it's declared const in the class, shouldn't the member definition need to be const as well I understand that from a code generation point of view it may be irrelevant, but it strikes me that seeing this would mean that the coder made a mistake since and would have intended for them to agree.



Answer this question

Shouldn't this generate a warning? (const, non-const)

  • CMCFelix

    No: this should not be an error (though it might warrant a warning). In C++ top-level cv-qualifiers in a parameter list do not impact the signature of a function (basically they are ignored) so the only place where const could have an effect would be on the definition - because in this case it would mean that you cannot write to the parameter.

  • Bart1

    I agree it is confusing. And it causes things to be thought well but done worse (hope this makes sense with my poor english).
    From my point of view if should be worth a level 4 warning.

    Just start a suggestions in
    http://lab.msdn.microsoft.com/productfeedback/Default.aspx



  • A kid

     Jonathan Caves MSFT wrote:
    No: this should not be an error

    Actually I never said it was an error, I was wondering if people agreed that it would be good if a warning were generated for that situation. As I said in my first post, I understand why it isn't an error and why it shouldn't be. But I think that code like that should generate a warning for the same reason as assigning within an if; it's legal code, but it's likely the user didn't mean to do what they did.

    Do other people agree

     


  • Shouldn't this generate a warning? (const, non-const)