How do you declare an interface in C++?

前端 未结 15 2564
借酒劲吻你
借酒劲吻你 2020-11-22 03:26

How do I setup a class that represents an interface? Is this just an abstract base class?

15条回答
  •  孤独总比滥情好
    2020-11-22 03:50

    Make a class with pure virtual methods. Use the interface by creating another class that overrides those virtual methods.

    A pure virtual method is a class method that is defined as virtual and assigned to 0.

    class IDemo
    {
        public:
            virtual ~IDemo() {}
            virtual void OverrideMe() = 0;
    };
    
    class Child : public IDemo
    {
        public:
            virtual void OverrideMe()
            {
                //do stuff
            }
    };
    

提交回复
热议问题