Re: [std-proposals] pure virtual functions

68 views
Skip to first unread message
Message has been deleted

Douglas Boffey

unread,
Apr 23, 2015, 10:43:42 AM4/23/15
to std-pr...@isocpp.org
On Mon, Apr 20, 2015 at 5:52 PM, Columbo <r....@gmx.net> wrote:
Is there an objective reason that
    virtual void f() = 0 {};
   
virtual void g() = 0 = default;
 
I don’t understand what you would expect these definitions to do.  To me, the ‘= 0’ indicating the functions are pure virtual and thus have no body, conflict with the {} or =default parts, which state otherwise.  Please could you elaborate.
 
should not be allowed? Is it possible to alter the definition of function-definition to allow pure-specifiers? It seems to me that parsers are fine with it,
and it's a hassle to define pure virtual destructors outside a class or class template. The changes necessary seem rather straightforward:
Change the grammar and make one or two semantical paragraphs (i.e. forbidding the use of pure-specifiers for anything but in-class virtual member function definitions).

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

Columbo

unread,
Apr 23, 2015, 10:46:10 AM4/23/15
to std-pr...@isocpp.org
(This is a double post. This thread did not appear until after I tried to post it a second time.)

Nevin Liber

unread,
Apr 23, 2015, 10:56:54 AM4/23/15
to std-pr...@isocpp.org
On 23 April 2015 at 09:43, Douglas Boffey <douglas...@gmail.com> wrote:
On Mon, Apr 20, 2015 at 5:52 PM, Columbo <r....@gmx.net> wrote:
Is there an objective reason that
    virtual void f() = 0 {};
   
virtual void g() = 0 = default;
 
I don’t understand what you would expect these definitions to do.  To me, the ‘= 0’ indicating the functions are pure virtual and thus have no body, conflict with the {} or =default parts, which state otherwise.  Please could you elaborate.

= 0 means that the base class is abstract and that the function must be overridden by the time we have a concrete derived class.

{} or = default gives an implementation to that function, which, for instance, may be called directly from a derived class.

They are not in conflict, and we can do that now.

Example:

struct Base {
    virtual void Alpha() = 0;
};

void Base::Alpha() { std::cout << "Base\n"; }

struct Derived : Base {
    void Alpha() override { std::cout << "Derived\n"; Base::Alpha(); }
};

--
 Nevin ":-)" Liber  <mailto:ne...@eviloverlord.com(847) 691-1404
Reply all
Reply to author
Forward
0 new messages