C++中的接口

文章目录

1 C++中的接口

满足下面条件的C++类被称为接口:

  • 类中没有定义任何的成员变量。
  • 所有的成员函数都是公有的。
  • 所有的成员函数都是纯虚函数。
  • 接口是一种特殊的抽象类。

接口程序示例:

#include <iostream>
#include <string>

using namespace std;

class Channel
{
public:
    virtual bool open() = 0;
    virtual void close() = 0;
    virtual bool send(char* buf, int len) = 0;
    virtual int receive(char* buf, int len) = 0;
};

int main()
{
    return 0;
}


参考资料:

  1. C++深度解析教程
发布了271 篇原创文章 · 获赞 28 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/SlowIsFastLemon/article/details/104282644