[英]How is std::vector<bool>::reference assigned to bool type in c++?
I know std::vector<bool>::reference
is a proxy class that is not apparent to users.我知道
std::vector<bool>::reference
是一个对用户不明显的代理类。
It is implicitly converted to bool when assigned to bool type.当分配给 bool 类型时,它被隐式转换为 bool。
How is it possible?这怎么可能? type
std::vector<bool>::reference
is far far from the type bool.类型
std::vector<bool>::reference
与类型 bool 相去甚远。
Is there some compiler work under the hood?是否有一些编译器在幕后工作?
Below is the code example下面是代码示例
...
std::vector<bool> v = { true, true, false, false, false };
std::vector<bool>::reference vr = v[1];
bool b = vr; // How is it possible ?
std::cout << b << std::endl;
...
std::vector<bool>::reference
定义operator bool
以允许隐式转换为bool
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.