This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
namespace + template
- To: gcc-bugs at gcc dot gnu dot org
- Subject: namespace + template
- From: Dimitri PAPADOPOULOS-ORFANOS <papadopo at shfj dot cea dot fr>
- Date: Thu, 20 Apr 2000 15:27:22 +0200 (MET DST)
- Reply-To: Dimitri PAPADOPOULOS-ORFANOS <papadopo at shfj dot cea dot fr>
Hi,
This is GCC 2.95.2 19991024.
I get the following error on the attached file:
$ g++ -c foo.cc
foo.cc: In method `me::rc_ptr<Derived>::rc_ptr<Base>(const me::rc_ptr<Base>&)':
foo.cc:54: instantiated from here
foo.cc:15: type `Derived' is not a base type for type `Base'
Removing the namespace or inverting some declarations makes the
error go away.
Dimitri Papadopoulos
namespace me { // remove namespace and it'll work
template <typename T>
class rc_ptr {
public:
explicit rc_ptr(T* p=0) : pointee(p) {
}
rc_ptr(const rc_ptr& x) : pointee(x.pointee) {
}
template <typename U>
rc_ptr(const rc_ptr<U>& x) : pointee(x.pointee) {
}
template <typename U>
friend inline rc_ptr<U> rc_cast(const rc_ptr<T>& x) {
return rc_ptr<U>((U*)dynamic_cast<U*>(x.pointee));
}
public:
T *pointee;
};
}
using me::rc_ptr;
class Base {
public:
virtual ~Base();
};
Base::~Base() {
}
class Derived : public Base {
public:
~Derived();
};
Derived::~Derived() {
}
int main() {
rc_ptr<Base> base; // switch these 2 lines and...
rc_ptr<Derived> derived; // ... the error message goes away
derived = rc_cast<Derived>(base);
return 0;
}