且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C++中抽象类和纯抽象类有什么区别?

更新时间:2022-06-09 01:44:57

抽象类至少有一个纯虚函数.这是标准的 C++ 术语.

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

有些人使用术语纯抽象类来描述一个只有纯虚函数(换句话说,没有数据成员也没有具体函数)的类.这相当于 Java 接口.

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).