dimanche 5 septembre 2021

how to create factory function (returning rvalue)

I wrote this piece of code:

class widget_12 {
public:
    //reference qualifiers example
    void dowork()&
    {
        std::cout << "*this is lvalue\n";
    }; // this version of dowork applies when *this is lvalue
    void dowork()&&
    {
        std::cout << "*this is rvlaue\n";
    }; // -||- *this is rvalue
    widget_12&& make_widget()
    {
        //TODO
    }
};

I want to test reference qualifiers, therefore I need to create a function that will return the rvalue of widget_12, could you show me how to do it?

I am basically trying to make this call:

make_widget().dowork();

Aucun commentaire:

Enregistrer un commentaire