|
PC-lint/FlexeLint Output | Reference Manual Explanation | Home Page bug1536.cpp
The programmer expected the printout to show a usage of 2 but instead got a usage of 4. The villain in the piece is obvious but why did a private value get modified by a public agent and why was the compiler silent?
bug1536.cpp lint Output
--- Module: bug1536.cpp
_
int &usage() { return count; }
bug1536.cpp(9) : Warning 1536: Exposing low access member 'A::count'
Reference Manual Explanation
1536 Exposing low access member 'Symbol' -- A member function is
returning the non-const address of a member either directly or
via a reference. Moreover, the member's access (such as private
or protected) is lower than the access of the function returning
the address. For example:
class X
{
private:
int a;
public:
int *f() { return &a; }
};
This looks like a breach of the access system [12, Item 30]. You
may lower the access rights of the function, raise the
accessibility of the member or make the return value a const
pointer or reference. In the above example you could change the
function to:
const int *f() { return &a; }
|
Previous Bug - Bug #534 - April 2001