This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
egcs-1.1.2 create abstract class
- To: egcs-bugs at egcs dot cygnus dot com
- Subject: egcs-1.1.2 create abstract class
- From: Carlo Wood <carlo at runaway dot xs4all dot nl>
- Date: Fri, 1 Oct 1999 03:49:53 +0200 (CEST)
Hiya, I got this one from a news group
From: raoulgough@my-deja.com
Newsgroups: comp.lang.c++.moderated
Subject: Compiler automatically generates abstract object (crash)
Date: 29 Sep 1999 02:44:17 -0400
~/c++/tests>g++ abstract.cc
~/c++/tests>a.out
virtfn from object at 0xbffff4b4
pure virtual method called
Reason being that g++ happily constructed an abstract object,
with a pure virtual function. I am not 100% sure this is bug
but I thought I'd let you know.
--
Carlo Wood <carlo@runaway.xs4all.nl>
abstract.cc:
#include <iostream>
struct Abstract
{
Abstract (int) {}
virtual void virtfn (void) const = 0; // pure virtual
};
struct Concrete : public Abstract
{
Concrete (int i) : Abstract (i) {}
virtual void virtfn (void) const
{
cout
<< "virtfn from object at "
<< static_cast<const void *> (this)
<< endl;
}
};
void call_virtfn (const Abstract& a)
{
a.virtfn();
}
void main ()
{
call_virtfn (Concrete (1)); // Ok, of course
call_virtfn (2); // Creates Abstract(2)
}