In the member initializer list, can I create a reference to a member variable not in the list?

前端 未结 3 759
离开以前
离开以前 2020-12-10 12:05

Consider:

#include 
#include 

class Foo
{
     public:
         Foo( char const * msg ) : x( y ) 
         {
             y =          


        
3条回答
  •  伪装坚强ぢ
    2020-12-10 12:42

    Can I safely create references to them as showcased?

    Yes, you can. The storage address of the member y is known regardless initialized it or not, so x(y) reference initialization is legal.

提交回复
热议问题