I've been wondering what does the following mean (code snippet taken from cppreference pimpl)
class widget::impl {
      ^^^^^^^^^^^^
   ...
};
What does a_class::another_class mean? Is that a namespace? Or is that an inner class declared out-of-the-main-class?
Or is that an inner class declared out-of-the-main-class?
Bingo. To be super clear, iit's actually an inner class defined outside the enclosing class.
It's a handy trick if you want a class with member-like access to your class as an implementation detail, but do not want to publish that nested class's definition to the clients of your class.
The :: operator is the scope resolution operator. It qualifies the scope of an expression. In your case, it qualifies the expression class impl with the scope widget, meaning the class impl that belongs to widget. Consider the following example which defines two impl classes at different scopes :
// global impl
class impl;
class widget
{
    // widget's impl
    class impl;
};
class widget::impl
{
    // Define widget's impl
};
class impl
{
    // Define global impl
};
The scope resolution operator allows you to clearly declare which class you are defining.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With