umimplemented pure virtual method
时间: 2023-10-01 22:10:28 浏览: 52
An unimplemented pure virtual method is a method in a C++ class that is declared as pure virtual, but not implemented in the class. A pure virtual method is a virtual function that does not have any implementation in the base class, and its implementation is provided by the derived class. When a pure virtual method is not implemented in a derived class, it remains unimplemented, and the derived class becomes an abstract class.
An abstract class cannot be instantiated, and it should be used as a base class for other classes that provide the implementation for the pure virtual methods. If a class contains an unimplemented pure virtual method, the compiler will generate an error message, and the class cannot be instantiated.
For example, consider a class called Shape that has a pure virtual method called area():
```
class Shape {
public:
virtual double area() const = 0; // pure virtual method
};
```
If a derived class, such as Circle, does not provide an implementation for the area() method, it will become an abstract class:
```
class Circle : public Shape {
public:
// no implementation for area() method
};
```
The compiler will generate an error message because the Circle class is abstract and cannot be instantiated. To fix this error, the Circle class should provide an implementation for the area() method:
```
class Circle : public Shape {
public:
double area() const override {
return 3.14 * radius * radius;
}
private:
double radius;
};
```
Now the Circle class can be instantiated, and it provides its own implementation for the area() method.