14

Example:

Iterators are pure abstractions: Anything that behaves like an iterator is an iterator.

What does it mean?

Melebius
  • 6,183
  • 4
  • 39
  • 52
Milad Khajavi
  • 2,769
  • 9
  • 41
  • 66
  • 7
    I don't think C++ makes such a distinction. Some users may do it if it is important in some context, but it often isn't. If that's the case, you should ask those users what they mean. – R. Martinho Fernandes Mar 06 '13 at 17:10
  • 1
    Where did you heard these terms? Ask them! – Nawaz Mar 06 '13 at 17:11
  • possible duplicate of [pure abstract class and interface](http://stackoverflow.com/questions/2091893/pure-abstract-class-and-interface) – unwind Mar 06 '13 at 17:11
  • The example quote "Iterators are pure abstractions" is yet to be answered as it deals with template concepts rather than polymorphism through vtables. – Johan Boulé Jul 14 '15 at 14:56

7 Answers7

30

An abstract class has at least one pure virtual function. This is standard C++ terminology.

Some people use the term pure abstract class to describe a class that has nothing but pure virtual functions (in other words, no data members and no concrete functions). This is equivalent to Java interfaces.

Now to your actual question:

Iterators are pure abstractions: Anything that behaves like an iterator is an iterator.

This has nothing to do with abstract classes (pure or otherwise). All it's saying is that anything that fulfils the iterator contract is an iterator. It doesn't even have to be a class (think pointers).

NPE
  • 486,780
  • 108
  • 951
  • 1,012
14

Nothing. The C++ Standard states only that a), a class is abstract if it has at least one pure virtual function, direct or inherited, and b), you can't instantiate an abstract class directly. There's no such thing as a pure abstract class.

Puppy
  • 144,682
  • 38
  • 256
  • 465
5

I would think a pure abstract class is the C++ equivalent of an interface.

See here:

A pure Abstract class has only abstract member functions and no data or concrete member functions. In general, a pure abstract class is used to define an interface and is intended to be inherited by concrete classes. It's a way of forcing a contract between the class designer and the users of that class. The users of this class must declare a matching member function for the class to compile.

Vlad
  • 18,195
  • 4
  • 41
  • 71
5

An abstract class is a class with some functionality but some that needs to be implemented, whereas a pure abstract class has none of its functionality implemented.

This is a bit like an interface in other languages such as C# and Java.

A pure abstract class would serve the purpose of specifying a 'contract' that concretions of the pure abstract class must adhere to.

Paul T Davies
  • 2,527
  • 2
  • 22
  • 39
2

Abstract Class *will atleast have one pure virtual function and can have data members.

Pure Abstract Class is just like an interface. Only pure virtual functions can be defined here. No data members or method definition can be done here.

For more information visit: (https://en.wikibooks.org/wiki/C%2B%2B_Programming/Classes/Abstract_Classes/Pure_Abstract_Classes)

CasperGhost
  • 117
  • 7
0

In C++ there is not pure abstract class. There are only abstract class and pure virtual function (function has been marked with = 0). Class with at least one pure virtual function becomes abstract. However pure virtual function can have implementation.

AnatolyS
  • 4,249
  • 18
  • 28
  • The way you say this is leading to confusion. In C++, "abstract" is not a keyword, neither "pure" is. As you said, virtual functions marked with " = 0" are called "pure virtual functions", which is another term for the same concept as "abstract functions". When a class *only* has pure/abstract functions, it's common terminology to refer to it as a "pure abstract class", although there is no special syntax in C++ to explicitly mark the whole class as such. As soon as you add anything else than pure/abstract functions to such a class, it's not "pure abstract" any more, but it still "abstract". – Johan Boulé May 16 '14 at 22:00
  • Sorry, your terminology does not meet C++ standard. But here is we are discussing C++ question. – AnatolyS Jul 02 '15 at 09:23
  • It's not because a word isn't used in the standard that is does not exist. It's not the goal of the standard to cover to whole OO terminology, or the various idioms people have come to use in C++. Applying the term "pure" to a class is perfectly legit. Perhaps we could say there is no technical difference in C++ between a pure and non-pure abstract base class ? – Johan Boulé Jul 14 '15 at 15:05
0

In your example, you're talking about Iterators. In C++, and more specifically in the standard library, the term Iterators doesn't refer to a pure abstract class but to what are called concepts. Concepts are used with templates rather than with virtual/inheritance-based polymorphism. Currently (C++11), concepts are only defined in the library documentation, i.e. they do not (yet) exist as part of the C++ language itself. The standard library documents concepts, for example the "Iterator" concept, as a set of requirements for any type/object to be accepted as a type parameter of a template that wants to work with an "Iterator". A set of requirements is defined in terms of which expressions are valid on an object, regardless of its type. It's a form of duck-typing. For example, see : http://en.cppreference.com/w/cpp/concept/Iterator

Johan Boulé
  • 1,936
  • 15
  • 19