Interview Zhenti C ++:. 1 What is an abstract class? What is a pure virtual function? Pure virtual function What is the difference with the average virtual function?

  • Pure virtual function: a function has only the function name and parameter list, no concrete realization; Syntax:virtual double GetArea()=0;
  • Abstract classes: In C ++, the class containing pure virtual function is referred to as an abstract class, it is not generated object. Abstract class is incomplete, it can only be used as a base class.
  • Man of few words said he understood it, I first see this is nonsense, I hope you gain something right.

 

Class 1 contains pure virtual function is an abstract class, the object can not be generated, only derived. He derived class pure virtual function is not rewritten, then it's derived class is an abstract class.

2 defines a pure virtual function is to allow the group of the class is not instantiated, such as instances of abstract data structure itself has no meaning. Alternatively meaning given implementation is not. The general form of a pure virtual function is defined as:
class name of the class {
Virtual return type function name (parameter list) = 0; // after the "= 0" is necessary, otherwise, to the virtual function
};
pure virtual function is a virtual function in the base class is described, it is not defined in the base class, the derived class defines require any own version. Pure virtual function to provide a common interface for the derived class parties.
Pure virtual function inherited from the base class, the derived class virtual function remains.

Guess you like

Origin www.cnblogs.com/qianrushi1/p/11595826.html