Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does the scope resolution operator used in a class name mean

I came across this code.

class SomeClass::OtherClass : public BaseClass
{
  // stuff in here
}

SomeClass is a class, so maybe OtherClass is a class that exists inside the scope of SomeClass? I've just never seen it done this way.

So, is that what it means?

like image 578
Chris Morris Avatar asked May 04 '12 16:05

Chris Morris


1 Answers

maybe OtherClass is a class that exists inside the scope of SomeClass?

Give yourself a checkmark. That is what it means.

This is used to subsequently define OtherClass after it was declared inside SomeClass:

class SomeClass {
    class OtherClass;
    OtherClass* GetOtherClassInstance() { ...}
};
class SomeClass::OtherClass {
} 

One might do this if the inner class only makes sense in the context of the exterior class.

class Vector {
  class Iterator;
  Iterator* GetStart();
};
class Vector::Iterator {
   details.
}

As mentioned elsewhere, the pimpl idiom is an excellent use of inner classes with deferred definition.

like image 119
Robᵩ Avatar answered Nov 02 '22 23:11

Robᵩ