为什么queue :: front()的返回值在queue :: pop()之后有效

 沈丶小浪_171 发布于 2023-03-19 22:02
  • php
  • 我是C++的新手并且遇到了所谓的 bug,但不知怎的,我的程序才有效..这是代码

    #include
    #include
    #include 
    
    
    int main()
    {
     string s ("cat");
     queue _queue;
     _queue.push(s);
     string & s1 = _queue.front();
     _queue.pop();
     // at this time s1 should become invalid as pop called destructor on s
     std::cout << s1 << std::endl;
     return 0;
    
     }
    

    它只是工作,即使s1是对无效对象的引用.有没有办法可以断言s1真的是指无效的对象?

    撰写答案
    今天,你开发时遇到什么问题呢?
    立即提问
    热门标签
    PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
    Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有