Access of a protected inner class via "auto". Using MSVC 14. Using the class name directly, I can't access the inner class yet using auto it works. Why?
class Car
{
class Driver;
public:
static Driver* createDriver()
{
return new Driver;
}
protected:
class Driver
{
public:
std::string name;
};
};
void test()
{
//these two lines fail to compile as Car::Driver is protected.
//Car::Driver* driver = Car::createDriver();
//driver->name = "John";
//but why does this work?
auto driver2 = Car::createDriver();
driver2->name = "John";
}