如何解决具有SFINAE /隐藏功能的模板转换运算符
我想在不同的类层次结构级别上使用模板转换运算符。我的问题是,即使SFINAE失败,基本转换运算符也会被隐藏。 有像使用这样的解决方法吗?
用于说明问题的示例代码(std :: is_same_v
#include <type_traits>
#include <iostream>
struct Bar
{
template<typename T>
operator T()
{
std::cout << "Bar::conv\n";
return {};
}
};
struct Foo : public Bar
{
template<
typename TOther,typename = std::enable_if_t<std::is_same_v<TOther,bool>>
>
operator TOther()
{
std::cout << "Foo::conv\n";
return {};
}
};
#include <iostream>
int main(){
Foo f;
bool b = f;
//error: operator bool is hidden?
int i = f;
return 0;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。