【问题标题】:How to avoid the error: terminate called after throwing an instance of 'std::logic_error' what(): basic_string::_S_construct null not valid如何避免错误:在抛出 'std::logic_error' 实例后调用终止 what(): basic_string::_S_construct null not valid
【发布时间】:2012-07-27 04:47:06
【问题描述】:
if(player!=NULL)
    player->shuffled();

我这样做是为了避免将空引用传递给字符串构造函数,但是在编译时仍然会出错。

【问题讨论】:

  • 你应该发布更多的上下文。
  • 异常的堆栈跟踪是什么?
  • 堆栈跟踪永远不会为此提供任何有用的信息,它都是与用户源代码没有任何关系的内部 c++ 库。否则是的,这个问题在 10 个月内不会有 56k 的浏览量!

标签: c++ libstdc++


【解决方案1】:

不知何故,您正在调用 std::string 构造函数,而 const char* 值为 NULL。

为了避免这个问题。不要那样做。

【讨论】:

  • 我在尝试string cmd = argv[1] 时没有给出任何参数,太聪明了。
猜你喜欢
  • 2023-01-17
  • 2019-10-26
  • 2017-04-11
  • 2017-12-13
  • 2019-02-08
  • 2019-06-23
  • 2022-01-11
  • 1970-01-01
  • 2021-04-04
相关资源
最近更新 更多