I have a base class and nested class with structure given below.
Base Hpp file
class Base{
private:
class Nested;
Nested* nested_ptr;
public:
Base();
Nested& GetNested();
Base Cpp file
Base::Base(){
nested_ptr = new Nested();
}
Base::Nested& Base::GetNested(){
return *nested_ptr;
}
The nested class is implemented in a separate file.
My compiler is apple clang 11.0 and cpp standard is 17.
When I try to access nested class via
Base base{}
Base::Nested& nested = base.GetNested();
I am getting compiler error. But when i try to access nested via
Base base{}
auto& nested = base.GetNested();
This compiles successfully. Is this feature portable or is it a bug in apple clang compiler.
Base base{};
base.GetNested().DoSomething();
This also compiles successfully.