This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

egcs-1.1.2 create abstract class


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)
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]