在Kenny Kerr先生的这一专栏中,他定义了一个结构和一个类似于这样的typedef:
struct boolean_struct { int member; };
typedef int boolean_struct::* boolean_type;
Run Code Online (Sandbox Code Playgroud)
那这个typedef是什么意思?
另一个问题是关于以下代码:
operator boolean_type() const throw()
{
return Traits::invalid() != m_value ? &boolean_struct::member : nullptr;
}
Run Code Online (Sandbox Code Playgroud)
"&boolean_struct :: member"是什么意思?
在VSCode的源文件中,有一些具有特定返回类型规范的函数,如下所示:
export function isString(str: any): str is string {
if (typeof (str) === _typeof.string || str instanceof String) {
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
所以我想知道"str is string"的目的是什么,而不仅仅是写"boolean".
我们可以在任何其他情况下使用"str is string"等吗?