C++ Function is Inaccessible

c++
12,867

Solution 1

It's inaccessible because it's protected instead of public.

protected means you can access it only from within the same, or a derived, class. Since you didn't indicate where your code was located, I'll just assume it is neither of those.

Solution 2

A protected function in a C++ can only be accessed by the class itself and derived classes, not outside the class, hence you're getting the error message that the function is inaccessible.

Solution 3

First off, it's marked as protected, so it will not be visible to non-derived classes.

Second, it's not static, and it looks to me as though you are calling it as if it were. Unless you have an object instance around named EventableObject you need an instance reference to call the function, i.e.,

EventableObject ev;
ev.RemoveEvent( this->ReadyUp );

Of course, that code makes little sense unless you had already added the event elsewhere, but hopefully you get the idea.

Share:
12,867
Author by

user795232

Updated on June 06, 2022

Comments

  • user795232 7 months

    I am wondering why this function is inaccessible.

    The function:

    class SERVER_DECL EventableObject
    {
    protected:
        void RemoveEvent(TimedEvent * ev);
    };
    

    Here is what I have:

    Event * ReadyUp;
    void Start()
    {
        static uint8 Tick = 1;
        if(Tick == 1)
        {
            NormalMessage("Starting Event..");
        }
        EventableObject.RemoveEvent(this->ReadyUp); // Inaccessible
    }
    

    EventableObject.RemoveEvent(this->BattlefieldReadyUp); // Inaccessible

    Is where I'm getting the error.