您的位置:首页 > 编程语言 > C语言/C++

引用与指针.C++

2008-05-31 14:10 267 查看
这篇文章展示C++中引用和指针的关系.

//==============================
typedef struct _tag_ref
{
 union{
  void *p;
  std::string &r;
 };
 _tag_ref(std::string &s):r(s){};
}REF;

std::string & refparam(REF& ref);

//==============================

std::string & refparam(REF& ref)
{
 std::cout << std::hex << ref.p << std::endl;
 return ref.r;
}

//==============================

 {
  std::string s("addr");
  REF ref(s);
  refparam(ref);
  std::cout << std::hex << &s << std::endl;
 }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  string hex struct c