这篇文章展示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;
}