55 lines
915 B
Plaintext
Raw Permalink Normal View History

== Why is this an issue?
By implementing class interfaces with member functions, the implementation retains more control over how the object state can be modified, and helps to allow a class to be maintained without affecting clients.
=== Noncompliant code example
2022-02-04 17:28:24 +01:00
[source,cpp]
----
class C
{
public:
int32_t b; // Noncompliant
protected:
int32_t c; // Noncompliant
private:
int32_t d; // Compliant
};
----
=== Compliant solution
2022-02-04 17:28:24 +01:00
[source,cpp]
----
class C
{
public:
int32_t getB() { return _b; }
void setB(int32_t b) { _b = b; }
protected:
int32_t getC() { return _c; }
void setC(int32_t c) { _c = c; }
private:
int32_t _b; // Compliant
int32_t _c; // Compliant
int32_t _d; // Compliant
};
----
== Resources
* MISRA {cpp}:2008, 11-0-1
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
=== duplicates: S3656
endif::env-github,rspecator-view[]