Error about inaccessable class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?ISO-8859-1?Q?Marcel_M=FCller?=

    Error about inaccessable class

    In the code below gcc says

    test.cpp: In constructor `SingleInfoDial og::SingleInfoD ialog(const
    PlayableSetBase &)':
    test.cpp:2: error: `class PlayableSetBase ' is inaccessible
    test.cpp:24: error: within this context

    Obviosly gcc does not manage to pass the parameter of type const
    PlayableSetBase & to the constructor of InfoDialog because there is a
    private base class with the same name. Is this really not allowed?


    Marcel


    -----
    class PlayableSetBase
    {
    };

    class OwnedPlayableSe t
    : public PlayableSetBase
    {public:
    OwnedPlayableSe t(const PlayableSetBase & r);
    };


    class InfoDialog
    // a member is not sufficient because of the destruction sequence
    : private OwnedPlayableSe t
    {protected:
    InfoDialog(cons t PlayableSetBase & key)
    : OwnedPlayableSe t(key)
    {}
    };

    class SingleInfoDialo g
    : public InfoDialog
    {public:
    SingleInfoDialo g(const PlayableSetBase & key)
    : InfoDialog(key) // <-- !!!
    {}
    };
  • Victor Bazarov

    #2
    Re: Error about inaccessable class

    Marcel Müller wrote:
    In the code below gcc says
    >
    test.cpp: In constructor `SingleInfoDial og::SingleInfoD ialog(const
    PlayableSetBase &)':
    test.cpp:2: error: `class PlayableSetBase ' is inaccessible
    test.cpp:24: error: within this context
    >
    Obviosly gcc does not manage to pass the parameter of type const
    PlayableSetBase & to the constructor of InfoDialog because there is a
    private base class with the same name. Is this really not allowed?
    It's probably a quirk of the lookup rules, which can be exacerbated by
    g++'s inability to interpret them correctly. Try supplying '::', like I
    show below.
    >
    >
    Marcel
    >
    >
    -----
    class PlayableSetBase
    {
    };
    >
    class OwnedPlayableSe t
    : public PlayableSetBase
    {public:
    OwnedPlayableSe t(const PlayableSetBase & r);
    };
    >
    >
    class InfoDialog
    // a member is not sufficient because of the destruction sequence
    : private OwnedPlayableSe t
    {protected:
    InfoDialog(cons t PlayableSetBase & key)
    : OwnedPlayableSe t(key)
    {}
    };
    >
    class SingleInfoDialo g
    : public InfoDialog
    {public:
    SingleInfoDialo g(const PlayableSetBase & key)
    Try replacing this with

    SingleInfoDialo g(const ::PlayableSetBa se& key)
    : InfoDialog(key) // <-- !!!
    {}
    };
    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask

    Comment

    • Andrey Tarasevich

      #3
      Re: Error about inaccessable class

      Marcel Müller wrote:
      In the code below gcc says
      >
      test.cpp: In constructor `SingleInfoDial og::SingleInfoD ialog(const
      PlayableSetBase &)':
      test.cpp:2: error: `class PlayableSetBase ' is inaccessible
      test.cpp:24: error: within this context
      >
      Obviosly gcc does not manage to pass the parameter of type const
      PlayableSetBase & to the constructor of InfoDialog because there is a
      private base class with the same name. Is this really not allowed?
      There's not just a private base class with that name, but also the name
      of that base class is implicitly introduced into the derived class'
      scope (it is called "base class name injection"). Class
      'PlayableSetBas e' is a base class of class 'OwnedPlayableS et', which
      means that 'PlayableSetBas e' is injected into the 'OwnedPlayableS et'
      scope, as if an invisible typedef declaration was there

      class OwnedPlayableSe t
      : public PlayableSetBase
      { public:
      ...
      typedef ::PlayableSetBa se PlayableSetBase ;
      ...
      };

      Now, whenever you use the unqualified 'PlayableSetBas e' in any derived
      class, it actually refers not to the file-scope name, but to that
      class-scope name implicitly declared in 'OwnedPlayableS et'.

      In your example, 'InfoDialog' inherits from 'OwnedPlayableS et'
      privately, meaning that now 'PlayableSetBas e' is private in
      'InfoDialog'. And finally, you are trying to access the private
      'PlayableSetBas e' from 'SingleInfoDial og', which causes the error.

      To fix the error, tell the compiler that you want to refer to the global
      'PlayableSetBas e' name, not the inherited private 'PlayableSetBas e' name.

      class SingleInfoDialo g
      : public InfoDialog
      {public:
      SingleInfoDialo g(const ::PlayableSetBa se& key)
      : InfoDialog(key)
      {}
      };
      >
      -----
      class PlayableSetBase
      {
      };
      >
      class OwnedPlayableSe t
      : public PlayableSetBase
      {public:
      OwnedPlayableSe t(const PlayableSetBase & r);
      };
      >
      >
      class InfoDialog
      // a member is not sufficient because of the destruction sequence
      : private OwnedPlayableSe t
      {protected:
      InfoDialog(cons t PlayableSetBase & key)
      : OwnedPlayableSe t(key)
      {}
      };
      >
      class SingleInfoDialo g
      : public InfoDialog
      {public:
      SingleInfoDialo g(const PlayableSetBase & key)
      : InfoDialog(key) // <-- !!!
      {}
      };
      --
      Best regards,
      Andrey Tarasevich

      Comment

      • =?ISO-8859-1?Q?Marcel_M=FCller?=

        #4
        Re: Error about inaccessable class

        Hi!

        Andrey Tarasevich wrote:
        Marcel Müller wrote:
        >In the code below gcc says
        >>
        >test.cpp: In constructor `SingleInfoDial og::SingleInfoD ialog(const
        > PlayableSetBase &)':
        >test.cpp:2: error: `class PlayableSetBase ' is inaccessible
        >test.cpp:24: error: within this context
        >>
        >Obviosly gcc does not manage to pass the parameter of type const
        >PlayableSetBas e& to the constructor of InfoDialog because there is a
        >private base class with the same name. Is this really not allowed?
        >
        There's not just a private base class with that name, but also the name
        of that base class is implicitly introduced into the derived class'
        scope (it is called "base class name injection"). Class
        'PlayableSetBas e' is a base class of class 'OwnedPlayableS et', which
        means that 'PlayableSetBas e' is injected into the 'OwnedPlayableS et'
        scope, as if an invisible typedef declaration was there
        [...]

        Thanks! This was the decisive hint.

        I was a bit confused because the error came at the line with the copy
        constructor invocation rather that the functions argument list.

        To fix the error, tell the compiler that you want to refer to the global
        'PlayableSetBas e' name, not the inherited private 'PlayableSetBas e' name.
        >
        class SingleInfoDialo g
        : public InfoDialog
        {public:
        SingleInfoDialo g(const ::PlayableSetBa se& key)
        : InfoDialog(key)
        {}
        };
        That works as expected.

        I only wonder a bit why

        SingleInfoDialo g::SingleInfoDi alog(const PlayableSetBase & key) {}

        does not give a similar error (assuming a suitable default constructor
        of InfoDialog). Types of member function arguments are normally resolved
        from within the class scope too.


        Marcel

        Comment

        Working...