문제

Paragraph 8.5.3/5 in n3797:

A reference to type “cv1 T1” is initialized by an expression of type “cv2 T2” as follows:

  • If the reference is an lvalue reference and the initializer expression

    • is an lvalue (but is not a bit-field), and “cv1 T1” is reference-compatible with “cv2 T2,” or

    • has a class type (i.e., T2 is a class type), where T1 is not reference-related to T2, and can be converted to an lvalue of type “cv3 T3,” where “cv1 T1” is reference-compatible with “cv3 T3” (this conversion is selected by enumerating the applicable conversion functions (13.3.1.6) and choosing the best one through overload resolution (13.3)),

...

English is not my native language, but the phrase in bold (my emphasis) seems to me to give the idea that T1 can be converted to an lvalue of type cv3 T3, which I believe is not correct. According to my understanding, T2 is the type who has to be convertible to cv3 T3, as the example:

struct B : A { operator int&(); } b;    
int& ir = B();

shows.

도움이 되었습니까?

해결책

You are not reading it correctly, this is how you should be reading it:

the initializer expression ... has a class type (i.e., T2 is a class type) ... and can be converted to an lvalue of type “cv3 T3,”

where the initializer expression refers back to:

[...]is initialized by an expression of type “cv2 T2” as follows

다른 팁

No, your interpretation is wrong.

  • T1 = the reference that is initialized
  • T2 = the class type
  • T3 = the lvalue that T2 can be converted to

The quoted snippet is stating that T2 (ie. the class type) can be converted to an lvalue of type T3 where T1 is reference-compatible with T3, but that T1 is not reference-related to T2.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top