class OtherClass;

class MyClass
{
public:
        const OtherClass* GetOther() const { return ( m_other_p ); }

protected:
        OtherClass* GetOther() { return ( m_other_p ); }

        OtherClass *m_other_p;

        friend class FriendClass;
};

In this case friend classes are allowed to access non-const data, but other
classes can only access the const data. The problem is that the compiler does
not recognize that other classes can call the GetOther() const function. It only
tries to use the non-const version and reports that the function is protected.
The two classes do have different C-V qualifiers so they have different
signatures. There is a workaround for this bug that you can declare a pointer to
a const MyClass and then call GetOther() which forces the compiler to look for a
const version of the function.

-- 
           Summary: Const function selection
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dsell at agleader dot com
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23904

Reply via email to