This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
g++ 3.4.0 : C++ templates' error messages
- From: Shelly Adhikari <shelly at interrasystems dot com>
- To: gcc at gcc dot gnu dot org
- Date: Tue, 11 May 2004 18:15:46 -0700
- Subject: g++ 3.4.0 : C++ templates' error messages
Hello Guys,
The following code compiled fine with gcc 3.3.3, but is giving me errors
in gcc 3.4.0. Uncommenting any of the two commented lines, removes the
error. Is the uncommented code incorrect [an explanation or citing the
relevant section of the C++ standard would be nice], or is it a bug in
3.4.0? If it is not a bug, the error message should be made clearer, if
possible.
template <class T> class A;
template <class T> class B;
template <class T> class C;
template <class T> class D;
template <class T> class A {
protected:
int a;
A() { }
virtual ~A() { }
virtual bool IsB() const = 0;
friend class D<T>;
friend class C<T>;
};
template <class T> class B : public A<T> {
protected:
int b;
B() { }
virtual ~B() { }
bool IsB() const { return true; }
bool PB() { return true; }
friend class C<T>;
friend class D<T>;
friend bool C<T>::CC(A<T>* a) const;
};
template <class T> class C : public A<T> {
protected:
int c0;
A<T>** c1;
C() { c1 = new A<T>* [10];}
virtual ~C() { delete [] c1;}
bool IsB() const { return false; }
//public:
bool CC(A<T>* a) const
{
if (IsB() == true)
{
B<T>* b = dynamic_cast<B<T>*>(c1[0]);
b->PB();
}
return true;
}
//friend class B<T>;
friend class D<T>;
};
template <class T> class D {
private:
C<T>* d;
public:
D() { d = new C<T>; };
~D() { delete d; };
bool DD() const { return d->CC(0); }
};
class T {
int t;
public:
T() { }
~T() { }
};
int main() {
D<T>* pdt;
pdt = new D<T>;
pdt->DD();
return 0;
}
shelly@redhat[1202] /usr/local/gcc3.3.3/bin/g++ b.cxx
shelly@redhat[1203] /usr/local/gcc3.4.0/bin/g++ b.cxx
b.cxx: In instantiation of `B<T>':
b.cxx:41: instantiated from `bool C<T>::CC(A<T>*) const [with T = T]'
b.cxx:56: instantiated from `bool D<T>::DD() const [with T = T]'
b.cxx:69: instantiated from here
b.cxx:38: error: `bool C<T>::CC(A<T>*) const [with T = T]' is protected
b.cxx:19: error: within this context
TIA
Shelly