当前位置: 首页 > news >正文

C++ //练习 16.14 编写Screen类模板,用非类型参数定义Screen的高和宽。

C++ Primer(第5版) 练习 16.14

练习 16.14 编写Screen类模板,用非类型参数定义Screen的高和宽。

环境:Linux Ubuntu(云服务器)
工具:vim

 

代码块
template <int H, int W> class Screen{public:using pos = string::size_type;Screen() = default;Screen(char c): contents(H * W, c) {}char get() const;char get(pos ht, pos wd) const;Screen &move(pos r, pos c);private:pos cursor = 0;string contents;
};template <int H, int W>
inline char Screen<H, W>::get() const{return contents[cursor];
}template <int H, int W>
inline char Screen<H, W>::get(pos ht, pos wd) const{pos row = ht * W;return contents[row + wd];
}template <int H, int W>
inline Screen<H, W>& Screen<H, W>::move(pos r, pos c){pos row = r * W;cursor = row + c;return *this;
}
http://www.lryc.cn/news/414691.html

相关文章:

  • 【Java】深度解析监视器的组成原理
  • Day14-Servlet后端验证码的实现
  • MySQL:数据库权限与角色
  • 等保测评练习卷25
  • 《python语言程序设计》2018第6章第28题 掷骰子 两个色子,分别是1到6
  • Java方法递归
  • 目标跟踪那些事
  • 【Git】 如何将一个分支的某个提交合并到另一个分支
  • 【嵌入式之RTOS】什么是消息队列
  • 9-springCloud集成nacos config
  • 市场主流 AI 视频生成技术的迭代路径
  • 移情别恋c++ ദ്ദി˶ー̀֊ー́ ) ——1.c++入门(2)
  • 【Python系列】深入理解 Python 中的 `nonlocal` 关键字
  • Flask目录结构路由重定向简单实例讲解——轻量级的 Python Web 框架
  • 破解PyCharm插件更新难题:让IDE焕发新生
  • cmake常用命令学习
  • K8S可视化管理平台KubeSphere
  • Bugku-CTF-聪明的php
  • 【MySQL进阶】MySQL主从复制
  • 本地部署文生图模型 Flux
  • 谷粒商城实战笔记-127-全文检索-ElasticSearch-整合-测试复杂检索
  • 解锁PyCharm:破解依赖库导入之谜
  • JSON-Viewer插件:json格式查看器
  • HDFS块信息异常,spark无法读取数据
  • TCP协议概述
  • SpringSecurity-3(认证和授权+SpringSecurity入门案例+自定义认证+数据库认证)
  • 英国AI大学排名
  • 渗透测试与高级攻防技术(二)网络安全技术的前沿探讨:渗透测试与高级攻防
  • Windows系统下安装mujoco环境的教程【原创】
  • 【秋招笔试】2024-08-03-科大讯飞秋招笔试题(算法岗)-三语言题解(CPP/Python/Java)