Where to put an interface class in C ++

I am new to C ++ programming and struggling with organizing my project. I have a class called StateManager that has a header file and a cpp file. Cpp contains all implementations.

If now I want to create an interface class:

class IStateManager
{
    public:
        virtual ~IStateManager() {}   
        virtual void SomeMethod {}
};

I know that interfaces really do not exist, as in C # or Java, but I want several classes to inherit from this "interface".

Does this class also need a header and a cpp file? Or can I just put it in the header file?

+4
source share
2 answers

, ++ . , "" ( , "" ). "" . ( - , , ), :

class IStateManager
{
    public:
        virtual ~IStateManager() {}
        virtual void SomeMethod() = 0;
        virtual void AnotherMethod() = 0;
};

class TheState : public IStateManager, public SomeOtherParentClass
{
    virtual void SomeMethod(); // Defined in this class
    virtual void AnotherMethod(); // Also defined in this class
    //..
};

.cpp IStateManager, , .

, : "" .cpp . , .h.

+4

. , . , , .

, virtual .

0

All Articles