Some tips about Abstract base classes and pure virtual functions

原创 2010年06月04日 22:49:00

  1、Often in a design, you want the base class to present only an interface for its derived classes, don't want anyone to actually create an object
  2、This is accomplished by making that class abstract, which happens if you give it at least one pure virtual function
  3、You can recognize a pure virtual function because it uses the virtual keyword and is followed by = 0. If anyone tries to make an object of an abstract class, the compiler prevents them.
  4、When an abstract class is inherited, all pure virtual functions must be implemented, or the inherited class becomes abstract as well.
  5、It's possible to provide a definition for a pure virtual function in the base class. You’re still telling the compiler not to allow objects of that abstract base class, and the pure virtual functions must still be defined in derived classes in order to create objects. However, there may be a common piece of code that you want some or all of the derived class definitions to call rather than duplicating that code in every function.

C++ - 纯虚函数(pure virtual) 和 抽象基类(abstract base class)

纯虚函数(pure virtual) 和 抽象基类(abstract base class)   本文地址:   纯虚函数(pu...
  • u012515223
  • u012515223
  • 2013年11月13日 14:54
  • 3975

Pure Virtual Functions and Abstract Classes

Original Link: Specific —>An abstra...
  • breeze_gao
  • breeze_gao
  • 2011年03月07日 13:21
  • 197

Abstract Classes and Pure Virtual Functions

1. What is an Abstract Class?Simply stated, an abstract class is a class which does notfully represe...
  • wswms
  • wswms
  • 2006年05月18日 16:32
  • 851

error C2253: 'RefCounted<T>' : pure specifier or abstract override specifier only allowed on virtual

环境:win7 32位,vs2010 源码: #include class RefCountedBase { public: void ref() { ++m_refCount; }...
  • dragoo1
  • dragoo1
  • 2015年05月07日 13:37
  • 1174

Pure Virtual Functions and Abstract Classes in C++

reference 1) A class i...
  • u011028408
  • u011028408
  • 2017年04月20日 11:29
  • 194

Python - abc (Abstract Base Classes)

为何使用抽象基础类? 抽象基础类,是一个接口,用于检测特定的方法。它比hasattr()方法更严格。定义一个基础类,你可以为子类定义一系列API。该方法很有用,尤其遇到一些第三方实现时,例如应...
  • u011130746
  • u011130746
  • 2015年01月21日 17:01
  • 1900


C++ 学习笔记之虚函数与纯虚函数
  • dbzhang800
  • dbzhang800
  • 2011年05月12日 23:56
  • 8579

【转载】一篇详尽分析C++“Pure Virtual Function Called”错误的文章

原文链接:   The C++ Source "Pure Virtual Function Ca...
  • u010665051
  • u010665051
  • 2013年09月21日 10:09
  • 1220

pure virtual method called

记录一个编写多线程程序时遇到的运行时错误:pure virtual method called 起因是写了一个多线程基类,里面有一个纯虚函数run,子类继承了这个run,重点就在纯虚函数上,因为是在...
  • freedomcheng
  • freedomcheng
  • 2014年12月26日 16:38
  • 1528

Python 2.7 Tutorial —— 类

.. _tut-classes: ******************Classes 类****************** Python's class mechanism adds classes...
  • ccat
  • ccat
  • 2010年10月05日 23:58
  • 2380
您举报文章:Some tips about Abstract base classes and pure virtual functions