How to get a pointer to a reference element?

Consider this code:

struct AA
{
    int& rr;
};

Is there a way to get a pointer (or possibly a link) before AA::rrto get this?

AA* aa;
auto mm = &AA::rr; // error: cannot create pointer to reference member ‘AA::rr’
aa ->* mm;

Also in gcc-7.0.1 decltype(AA::mm)is only int&. This is according to the standard? And does that make sense?


EDIT

Sorry guys, I did not formulate the question very well. There are no complaints that the links are not objects or that there is no pointer to the link. The goal is pretty selfish. Given struct AA { int& rr; };, I just want to have a function like this:

template < typename Class, typename Member >
void test(Member Class::*) { }

that when you call test(&AA::rr), I want to be Classwas AA, and Memberequal to int&or int. Therefore, I don’t even need the pointer itself, but its type, which will allow us to get the class type and member type.

+4
2

()?

( ). ++ , " ". , , , .

addressof , , , , .

+5

picture

, , , .

, , . , cout & rx & x, .

, , , ,

+2

Source: https://habr.com/ru/post/1669185/


All Articles