samedi 6 juin 2020

Could somebody explain the functions of a member function with the delaration 'explicit operator const GUID_t&() const'?

What's the function of 'operator const GUID_t&() const' in the code snippet below.

It's quoted from a wellknown open source project,so i don't doublt the correctness.It does not look like ordenary operator overload,eg:CTest operrator(CTest&&), which you could clearly know the return type.Is there a term for this kind of usage?I would be grateful to have some help with this question.It would be better that if you could give a few such examples.

struct GUID_t{};
struct InstanceHandle_t
{
    explicit operator const GUID_t&() const
    {
        return *reinterpret_cast<const GUID_t*>(this);
    }
}

Aucun commentaire:

Enregistrer un commentaire