http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56257
Bug #: 56257
Summary: std::vector allows access to the elements of
_Vector_base
Classification: Unclassified
Product: gcc
Version: 4.6.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
AssignedTo: [email protected]
ReportedBy: [email protected]
To my complete consternation, a student of mine came by and showed me some code
her wrote that essentially looked like this:
-----------------------
#include <vector>
struct X :
public std::vector<int>
{
X()
{
this->_M_impl;
}
};
-----------------------
While accessing the implementation details of std::vector was a clever
optimization in his case, it's certainly an end-run around the encapsulation
principle. It also doesn't lead to portable code.
Is it intentional that the derivation of std::vector from _Vector_base is only
protected and not private?
Best
W.