lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 084f1b49 5/5: Make a different virtual pure


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 084f1b49 5/5: Make a different virtual pure
Date: Mon, 11 Jul 2022 22:53:09 -0400 (EDT)

branch: master
commit 084f1b493d38aea81cb6efa174751bbb82ebaef2
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Make a different virtual pure
    
    When at least one virtual must be declared pure because a base class
    shouldn't be instantiated directly, it is conventional to put the
    pure-specifier on the dtor. This commit challenges that convention.
    
    C++20 says [class.abstract/2]: "A function declaration cannot provide
    both a pure-specifier and a definition." Formerly, the dtor was
    declared as pure, and elsewhere defined as defaulted, with comments
    in both places. Code that requires comments is worse than code that
    does not. Moving the pure-specifier made comments unnecessary. This
    is therefore a pure improvement.
    
    Forwent the usual space before "0" because it would have made the line
    81 characters wide. To avoid writing a line wider than 80 characters,
    in a file where that limit is otherwise respected except for the
    copyright dates, is more important than writing that customary space.
---
 datum_sequence.cpp |  9 ---------
 datum_sequence.hpp | 10 ++--------
 2 files changed, 2 insertions(+), 17 deletions(-)

diff --git a/datum_sequence.cpp b/datum_sequence.cpp
index a95bc4b0..cd469978 100644
--- a/datum_sequence.cpp
+++ b/datum_sequence.cpp
@@ -46,15 +46,6 @@ datum_sequence::datum_sequence(std::string const& s)
     assert_sanity();
 }
 
-/// Implementation of pure virtual destructor.
-///
-/// Neither this explicitly-defaulted implementation nor any other can
-/// be written inside the class definition because C++11 [10.4/3] says
-/// "a function declaration cannot provide both a pure-specifier and a
-/// definition".
-
-datum_sequence::~datum_sequence() = default;
-
 datum_sequence& datum_sequence::operator=(std::string const& s)
 {
     datum_string::operator=(s);
diff --git a/datum_sequence.hpp b/datum_sequence.hpp
index ede36608..b1e1a313 100644
--- a/datum_sequence.hpp
+++ b/datum_sequence.hpp
@@ -54,12 +54,6 @@
 ///
 /// Still others permit both numbers and keywords. Specified amount,
 /// e.g., must accommodate numeric entry.
-///
-/// The dtor is pure because this class should not be instantiated.
-/// Most of the other virtuals would normally be overridden in any
-/// derived class, but aren't pure because that requirement is obvious
-/// and it's convenient to invoke them in assert_sanity() to validate
-/// ctor postconditions.
 
 class datum_sequence
     :public datum_string
@@ -72,7 +66,7 @@ class datum_sequence
     datum_sequence(datum_sequence&&) = default;
     datum_sequence& operator=(datum_sequence const&) = default;
     datum_sequence& operator=(datum_sequence&&) = default;
-    ~datum_sequence() override = 0; // Pure: see note above.
+    ~datum_sequence() override = default;
 
     datum_sequence& operator=(std::string const&);
 
@@ -81,7 +75,7 @@ class datum_sequence
     virtual bool numeric_values_are_allowable() const;
     virtual bool keyword_values_are_allowable() const;
     virtual std::string const default_keyword() const;
-    virtual std::map<std::string,std::string> const allowed_keywords() const;
+    virtual std::map<std::string,std::string> const allowed_keywords() const 
=0;
 
     bool equals(datum_sequence const&) const;
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]