除了定义数据和函数成员之外,类还可以定义自己的局部类型名字.如果为std::string::size_type提供一个类型别名,那么Screen类将是一个更好的抽象:

  class Screen{

  public:

    typedef std::string::size_type index;

  private:

    std::string contents;

    index cursor;

    index height, width;

}

在哪都能用的 Screen::index 这样就行了;

posted on 2012-07-16 18:11  MarvinGeng  阅读(148)  评论(0编辑  收藏  举报