How do I set up a class that represents the interface? Can I just write an abstract class?
c++ inheritance interface abstract-class pure-virtual
Create a class that has pure virtual methods. A class with pure virtual method as a member function is called an abstract class The abstract class cannot create an instance because it has an undefined member function.
You can inherit this abstract class and override virtual methods.
For the pure virtual method, you can add "= 0" after the virtual function as follows:
// Abstract class to write as interface
class Parent
{
public:
virtual ~Parent() {}
virtual void functionToOveride() = 0;
};
class Child : public Parent
{
public:
virtual void functionToOveride()
{
///...
}
};
© 2024 OneMinuteCode. All rights reserved.