mercredi 31 août 2016

Is it possible to get reference to 'this' pointer in class body without using the class name?

Here is what I tried:

class i_really_dont_wanna_to_use_this_class_name_for_reference_type_of_this
{
    //get this:
    auto get_this() -> decltype(this) {return this;}

    //now, somehow declare reference do value returned by get_this()
    //here is what I tried but failed
    auto * const & this_ref = get_this(); //error, invalid use of auto
    decltype(this)& this_ref = get_this() //error, invalid use of this     
}

Is it even possible?

Aucun commentaire:

Enregistrer un commentaire