Pure Virtual Functions and Abstract Classes in C++
2017-04-20 11:29
549 查看
reference http://quiz.geeksforgeeks.org/pure-virtual-functions-and-abstract-classes/
1) A class is abstract if it has at least one pure virtual function.
2) We can have pointers and references of abstract class type.
3) If we do not override the pure virtual function in derived class, then derived class also becomes abstract class.
4) An abstract class can have constructors.
For example, the following program compiles and runs fine.
Interface vs Abstract Classes:
An interface does not have implementation of any of its methods, it can be considered as a collection of method declarations. In C++, an interface can be simulated by making all methods as pure virtual.
1) A class is abstract if it has at least one pure virtual function.
2) We can have pointers and references of abstract class type.
3) If we do not override the pure virtual function in derived class, then derived class also becomes abstract class.
4) An abstract class can have constructors.
For example, the following program compiles and runs fine.
{ |
Interface vs Abstract Classes:
An interface does not have implementation of any of its methods, it can be considered as a collection of method declarations. In C++, an interface can be simulated by making all methods as pure virtual.
相关文章推荐
- Pure Virtual Functions and Abstract Classes
- Abstract Classes and Pure Virtual Functions
- [C++] OOP - Virtual Functions and Abstract Base Classes
- Some tips about Abstract base classes and pure virtual functions
- [C++] Pure Virtual Function and Abstract Class
- c / c++ virtual function and pure virtual function summarize
- Think before you code, Virtual Functions in C++
- Using dllimport and dllexport in C++ Classes
- Can static functions be virtual in C++?
- c++ friend functions and inline functions
- Standard C++ Programming: Virtual Functions and Inlining
- C++: Pure Virtual Functions
- C++ - 纯虚函数(pure virtual) 和 抽象基类(abstract base class)
- Error 2259 : cannot instantiate abstract class with one or more pure virtual functions
- Why do many Collection classes in Java extend the abstract class and implement the interface as well
- (转载)Comparing C++ and C (Inheritance and Virtual Functions)
- usage of fscanf and other read functions in C/C++
- C++ - 纯虚函数(pure virtual) 和 抽象基类(abstract base class)
- Abstract Classes and Factory Design Pattern in Python
- How do virtual functions work in C++?