From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24106 invoked by alias); 31 Mar 2008 07:11:05 -0000 Received: (qmail 23487 invoked by uid 48); 31 Mar 2008 07:10:15 -0000 Date: Mon, 31 Mar 2008 07:11:00 -0000 Message-ID: <20080331071015.23486.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug c++/35772] GCC allows defining pure virtual functions In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "yuriry at gmail dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-03/txt/msg02527.txt.bz2 ------- Comment #2 from yuriry at gmail dot com 2008-03-31 07:10 ------- Hi Björn, Thank you for the link and setting me straight. You are correct, implementation of a pure virtual function by the class that declares it makes sense. It is just the class itself remains abstract. Earlier today I had a problem with dynamic library loading and it disappeared only after I removed an implementation of a pure virtual method from a declaring class. I thought this was a problem, but it looks like I need to look more at what was happening. Regards, Yuri (In reply to comment #1) > Hi yuri, > > I think, this is perfectly correct code and GCC is right in accepting it. First > of all, see "Effective C++" issue 14 about the pure virtual destructor. Then > see here: > > http://en.wikipedia.org/wiki/Virtual_function#Abstract_classes_and_pure_virtual_functions > > > Although pure virtual methods typically have no implementation in the class > that declares them, pure virtual methods in C++ are permitted to contain an > implementation in their declaring class, providing fallback or default > behaviour that a derived class can delegate to if appropriate. > > > Regards, > Björn Herwig > > (In reply to comment #0) > > GCC compiles the code below without any error: > > > > //---------------------------------- > > class A { > > protected: > > virtual void foo() const = 0; > > }; > > > > // Defining pure virtual functions should not be allowed. > > void A::foo() const > > { > > } > > //---------------------------------- > > > -- yuriry at gmail dot com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution| |INVALID http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35772