天生舞男

我喜欢谦虚的学习各种...,希望自己能坚持一辈子,因为即使一张卫生巾也是有它的作用.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

The difference with pure virtual fuction and virtual fuction

Posted on 2005-09-04 18:00  天生舞男  阅读(509)  评论(0编辑  收藏  举报
virtual fuction:

class WageEmployee
{
public:
  virtual float computePay();
};

class SalesPerson : public WageEmployee
{
public:
  float computePay();
};

    A virtual function is a member function that you expect to be redefined in derived classes.  When you refer to a derived class object using a pointer or a reference to the base class, you can call a virtual function for that object and execute the derived class's version of the function.

pure virtual fuction:

class WageEmployee
{
public:
  virtual float computePay() = 0;
};

class SalesPerson : public WageEmployee
{
public:
  float computePay();
};

the difference  is
1.
if a class have a pure virtual fuction ,the the class is a abstract class
can't instance.
but contain virtual fuction can instance