I want to know why the error occurred in the following code. I use clang-17 for compilation. Compiling this code using gcc11.4.0 will also result in an error message I guess it should be related to the type conversion operator, but I cannot pinpoint the specific reason。
class A
{
public:
template <class _Ty>
explicit operator _Ty() const noexcept
{
return c;
}
std::string c = "sdafasd";
};
int main()
{
A a;
const std::string &str = static_cast<const std::string &>(std::move(a));
}
I change the code to the following so that there will be no errors:
class A
{
public:
template <class _Ty>
explicit operator _Ty&() const noexcept
{
return c;
}
std::string c = "sdafasd";
};
Why is this happening