阅读背景:

在成员初始化列表中,我可以创建对不在列表中的成员变量的引用吗?

来源:互联网 

Consider:

#include <string>
#include <iostream>

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

         std::string const & x;

     private:
         std::string y;
};

int main( int argc, char * argv[] )
{
    if ( argc >= 2 )
    {
        Foo f( argv[1] );
        std::cout << f.x << std::endl;
    }
}
#include <string>
#include <iostrea



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: