See the following code example:

#include <iostream>

template <typename tn>
class a{
protected:
        tn bar;
public:
        a(tn bar){
                this->bar=bar;
        }
        virtual tn getBar(){
                return bar;
        }
};

template <typename tn>
class b : public a<tn>{
private:
        void add(tn baz); 
public:
        b(tn bar, tn baz)
                : a<tn>(bar)
        {
                add(baz);
        }
};

template <typename tn>
void b<tn>::add(tn baz){
        bar+=baz;
}

int main(){
        b<unsigned> test(7,5);
        std::cout << test.getBar() << std::endl;
        return 0;
}

This gives
test.cpp: In member function `void b<tn>::add(tn)':
test.cpp:30: error: `bar' undeclared (first use this function)
test.cpp:30: error: (Each undeclared identifier is reported only once for each
function it appears in.)
As well as it's (in my and the opinion of ##c++) valid ANSI C++.

-- 
           Summary: protected members of templated base class not accessible
                    in derived class
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tonne2005 at gehheimdienst dot de
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i386-redhat-linux
  GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux


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

Reply via email to