Why can I use auto on a private type?

前端 未结 4 528
悲哀的现实
悲哀的现实 2020-11-22 09:26

I was somehow surprised that the following code compiles and runs (vc2012 & gcc4.7.2)

class Foo {
    struct Bar { int i; };
public:
    Bar Baz() { retu         


        
4条回答
  •  花落未央
    2020-11-22 09:41

    Access control is applied to names. Compare to this example from the standard:

    class A {
      class B { };
    public:
      typedef B BB;
    };
    
    void f() {
      A::BB x; // OK, typedef name A::BB is public
      A::B y; // access error, A::B is private
    }
    

提交回复
热议问题