我用C++编写代码,std::unique_ptr u用来处理std::string资源,我想取消引用,u以便我可以传递std::string给std::string复制构造函数的调用:
std::string* copy = new std::string( /*dereference u here*/ );
Run Code Online (Sandbox Code Playgroud)
我知道new或std::string复制构造函数可以抛出,但这不是我的观点.我只是想知道解除引用u是否已经抛出异常.我觉得奇怪,operator*是不是标志着noexcept,而std::unique_ptr方法get实际上是标记noexcept.换一种说法:
*( u.get() )
Run Code Online (Sandbox Code Playgroud)
是noexcept一个整体而言
*u
Run Code Online (Sandbox Code Playgroud)
不是.这是标准中的缺陷吗?我不明白为什么会有区别.有任何想法吗?