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