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

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

时间:2024-08-04 08:55:45浏览次数:9  
标签:用非 16.14 Screen pos char template contents row

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;
}

标签:用非,16.14,Screen,pos,char,template,contents,row
From: https://blog.csdn.net/navicheung/article/details/140817169

相关文章

  • 易优CMS模板标签screening文档筛选指定自定义字段读取筛选条件
    [基础用法]标签:screening描述:用于在列表页文档筛选场景(支持文章、产品、视频、图集以及自定义等模型)用法:{eyou:screeningid='field'currentclass='active'alltxt='不限'}<divclass="row"><divclass="filter-box"><......
  • 为什么Python要对引用非容器类型的类型实现循环GC
    检查文档:支持循环垃圾收集Python对检测和收集涉及循环引用的垃圾的支持需要对象类型的支持,这些对象类型是其他对象的“容器”,这些对象也可能是容器不存储对其他对象的引用或仅存储对原子类型(例如数字或字符串)的引用的类型不需要为垃圾收集提供任何显......
  • Windows Defender SmartScreen 已阻止启动一个未识别的应用
    对于软件开发者或者软件开发公司来说,发布应用程序后会面临一个难题,那就是用户在下载此应用程序时,SmartScreen会弹出“WindowsDefenderSmartScreen已阻止启动个未识别的应用,运行此应用可能会导致您的电脑面临风险” 的警告,这种警告不利于用户信任,还有可能会减少用户下载率......
  • 易优CMS网站screening筛选标设置与调用标签
    {eyou:screeningid='field'currentstyle='active'addfields='danxuan'alltxt='不限'}<divclass='row'><divclass='filter-box'>{eyou:volistname='$field.list'id='vo&......
  • [1038] Move the Adobe Acrobat to the left screen if it is in the right screen
    Inpython,itisdifficulttocaptureit.Butwecanuseanotherwaytodothis.Eachtime,whenweopentheAdobeAcrobat,itwillshowsomethinglikethis:Ifitisintheleftscreen,thebluearrowshouldbeinthespecificarea.Sowecanuse pyauto......
  • Unity入门之重要组件和API(4) : Screen
    Screen类主要处理屏幕相关的操作。1.静态属性1.1常用属性【设备分辨率】Resolutionresolution=Screen.currentResolution;print("设备分辨率宽:"+resolution.width+"高:"+resolution.height);【屏幕窗口的宽高】这里得到的是当前窗口的宽高,不是设备分辨率的宽......
  • SCREEN获取鼠标位置实现删除插入数据功能
     1、获取鼠标光标位置DATA:gv_lineTYPEi.gv_index=tc_material-top_line+gv_line-1.CLEAR:gs_tc_material_wa.READTABLEgt_tc_material_itabINDEXgv_indexINTOgs_tc_material_wa.2、点击删除按钮弹出确认提示框CALLFUNCTION'POPUP_TO_CONFIRM......
  • 网站被SmartScreen标记为不安全怎么办?
    在互联网时代,网站的安全性和可信度是用户选择是否继续访问的重要因素之一,然而,网站运营者偶尔会发现使用Edge浏览器访问网站时,会出现MicrosoftDefenderSmartScreen(以下简称SmartScreen)提示网站不安全的情况。为什么SmartScreen会提示网站不安全?作为网站运营者,网站被SmartScree......
  • 【Shader】ComputeScreenPos 的使用
     在顶点着色器中使用ComputeScreenPos.使用tex2Dproj搭配screenPos来按屏幕uv采样屏幕材质(如_CameraDepthTexture和_CameraNormalTexture).ComputeScreenPos:接受的输入顶点在裁剪空间(经过MVPmatrix的变换)的位置将输出从  ---转自 ComputeSc......
  • ScreenToGif:一款开源免费且好用的录屏转Gif软件
    ScreenToGif介绍GitHub上的介绍:此工具允许您记录屏幕的选定区域、来自网络摄像头的实时提要或来自草图板的实时绘图。之后,您可以编辑动画并将其保存为gif、apng、视频、psd或png图像。在平常写公众号的过程中,经常有录屏转Gif的需求,我就是使用ScreenToGif做的。在截止写这......