This question already has an answer here:
- Why can I use auto on a private type? 2 answers
Consider the following code:
class Main
{
private:
class Inner
{
public:
void DoSomething() {}
};
public:
static Inner* CreateInner() { return new Inner(); }
};
It is impossible to compile the following:
Main::Inner* pInner = Main::CreateInner();
pInner->DoSomething();
Because we'll get a compiler error 'C2248: cannot access private class decalred in class Main'
However, using the following syntax will compile and execute smoothly:
auto pInner = Main::CreateInner();
pInner->DoSomething();
Suddenly, (to my surprise, anyway...), the inner private class is 'visible' to the outside world...
Does anyone aware to this compiler behavior? Is it considered 'valid' to use the auto keyword according to the C++11 standard in this case, or is it some kind of a bug?
It behaves as described on both:
- Visual Studio 2010 - platform toolset v100
- Visual Studio 2013 - platform toolset v120
Any thoughts?
Thanks!
Aucun commentaire:
Enregistrer un commentaire