This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
dynamic_cast bug? Feature?
- To: gcc-bugs at gcc dot gnu dot org
- Subject: dynamic_cast bug? Feature?
- From: Bruce Ide <nride at uswest dot net>
- Date: Thu, 20 Jul 2000 20:43:53 -0600
I've got a bit of C++ code here that exits with a compiler error in GCC
2.95.2. Shouldn't this compile and have dynamic_cast return a 0 for the
class the compiler's erroring on?
--
Bruce Ide nride@uswest.net
If trees screamed would we be as quick to cut them down? Possibly,
if they screamed all the time.
#include <iostream>
#include <string>
class Pinger {
public:
Pinger() {};
virtual ~Pinger() {};
virtual void ping() { cout << " Ping" << endl; } ;
};
class CanPing1 : public Pinger {
public:
CanPing1(char *data) {my_data.append(data);}
~CanPing1() {};
string my_data;
};
class CanPing2 : public Pinger {
public:
CanPing2(char *data) {my_data.append(data);}
~CanPing2() {};
string my_data;
};
class CantPing {
public:
CantPing(char *data) {my_data.append(data);}
~CantPing() {}
string my_data;
};
template <typename T> void ping(T *object)
{
Pinger *s;
s = dynamic_cast<Pinger *>(object);
if (s) {
s->ping();
} else {
cout << " can't ping" << endl;
}
}
int main()
{
CanPing1 first("CanPing1");
CanPing2 second("CanPing2");
CantPing third("CantPing");
cout << first.my_data;
ping(&first);
cout << second.my_data;
ping(&second);
cout << third.my_data;
ping(&third);
}