Are abstract methods and pure virtual functions the same thing?

前端 未结 5 1059
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-24 05:05

As far as I know, both abstract methods and pure virtual functions do NOT provide any functionality ... So can we say they\'re both the same thing ?

Also, suppose a

5条回答
  •  醉梦人生
    2020-12-24 05:37

    Yes, they are the same thing. In C++, an abstract method is just another way of describing the characteristics of a pure virtual function. Both just mean a method with no implementation provided that needs to be implemented in a sub-class before the class can actually be instantiated.

    The situation with pure virtual functions and abstract classes in C++ is similar as they essentially mean exactly the same thing. Any abstract class must have at least 1 pure virtual function or else it could be instantiated and wouldn't be abstract. Likewise, any class with at least 1 pure virtual function must be abstract because it needs to be extended so that method can actually be implemented.

    Therefore, a class is abstract if and only if it contains at least 1 pure virtual function/abstract method.

    Later on, languages like Java and C# made things like this more explicit, allowing a special keyword to define a class abstract rather than the presence of a pure-virtual function. C++ lets you do the same things as these languages, but they're just a little more explicit about it. :D

提交回复
热议问题