指针与引用区别
用指针传递
class Building
{
public:
Building()
{
this->m_SittingRoom = “客厅”;
this->m_BedRoom = “卧室”;
}
public:
string m_SittingRoom;
private:
string m_BedRoom;
};
void goodGay(Building * building)
{
cout << building->m_SittingRoom << endl;
}
void test01()
{
Building b;
goodGay(&b);
}
用引用传递
class Building
{
public:
Building()
{
this->m_SittingRoom = “客厅”;
this->m_BedRoom = “卧室”;
}
public:
string m_SittingRoom;
private:
string m_BedRoom;
};
void goodGay(Building & building)
{
cout << building.m_SittingRoom << endl;
}
void test01()
{
Building b;
goodGay(b);
}