Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a pure virtual function in the C++ Standard Library?

In Nicola Gigante's lecture in 2015, he mentions (at the beginning) that there are no pure virtual functions in the Standard Library (or he's not aware of any). I believe that Alex Stepanov was against this language feature but since the initial STL design, have any pure virtuals creeped into the Standard library?

FWIW (and correct me if I'm wrong) the deleters in unique pointers ultimately use virtual dispatching in most implementations but these are not pure virtuals.

like image 347
Lorah Attkins Avatar asked Jan 26 '16 23:01

Lorah Attkins


People also ask

What is a pure virtual function in C?

A pure virtual function or pure virtual method is a virtual function that is required to be implemented by a derived class if the derived class is not abstract. Classes containing pure virtual methods are termed "abstract" and they cannot be instantiated directly.

Which class has no pure virtual function?

A class is abstract if it has at least one pure virtual function. Unfortunately, there are cases when one cannot add a pure virtual method to a class to turn it in an abstract one and still he doesn't want users to be able to instantiate that class.

Which class has pure virtual function?

An abstract class is a class in C++ which have at least one pure virtual function.

Does C have virtual?

In C, virtual function calls look unlike any other kind of function call. For example, a call to the virtual area function applied to a shape looks like: shape *s;~~~s->vptr->area(s);


2 Answers

[syserr.errcat.overview] has std::error_category

class error_category {   virtual const char* name() const noexcept = 0;   virtual string message(int ev) const = 0; }; 

There are no others in C++14.

like image 53
Igor Tandetnik Avatar answered Oct 14 '22 18:10

Igor Tandetnik


C++17 adds std::pmr::memory_resource in [mem.res.class] to the one in C++14, with the following private pure virtual functions:

class memory_resource {     virtual void* do_allocate(size_t bytes, size_t alignment) = 0;     virtual void do_deallocate(void* p, size_t bytes, size_t alignment) = 0;     virtual bool do_is_equal(const memory_resource& other) const noexcept = 0; }; 

And yes, private virtual functions can be overridden.

like image 33
P.W Avatar answered Oct 14 '22 17:10

P.W