This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

c++/2617: template class derived from parent refuses access to protected fields



>Number:         2617
>Category:       c++
>Synopsis:       template class derived from parent refuses access to protected fields
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Apr 23 13:16:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Sengan
>Release:        egcs-2.91.66
>Organization:
>Environment:
linux, redhat 6.1
>Description:
I believe SmartPtr::operator=() should be allowed to access pointee since SmartPtr is a child of SuperSmartPtr, and pointee is protected. However line "J=C" fails to compile.


class SuperSmartPtr {
  public:
    SuperSmartPtr(void* p) : pointee(p) {}
    SuperSmartPtr(const SuperSmartPtr& rhs) { pointee = rhs.pointee; }
    virtual ~SuperSmartPtr() {}

  protected:
    void* pointee;
};


template <class T>
class SmartPtr : public SuperSmartPtr {
  public:
    SmartPtr(T* realPtr = 0) : SuperSmartPtr(realPtr) {}
    ~SmartPtr() {}
    SmartPtr& operator=(const SuperSmartPtr& rhs) { pointee = rhs.pointee; }
};

int main()
{
  char buf[5] = "abcd";

  SmartPtr<char> C( buf);
  SmartPtr<int> J((int*) 0);
  J = C;

  return 0;
}
>How-To-Repeat:
g++ <above file>


I also tried this file on http://www.codesourcery.com/gcc-compile.shtml, but obtain:
/usr/tmp/@12493.7.cc: In member function `SmartPtr& SmartPtr::operator=(const SuperSmartPtr&) [with T = int]':
/usr/tmp/@12493.7.cc:26:   instantiated from here
/usr/tmp/@12493.7.cc:8: `void*SuperSmartPtr::pointee' is protected
/usr/tmp/@12493.7.cc:17: within this context

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]