Last active
January 2, 2016 08:59
-
-
Save zbjxb/8280488 to your computer and use it in GitHub Desktop.
给胖子演示一下c++类成员函数中能访问同类对象的私有数据成员。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Car { | |
public: | |
Car(int num, const string& engineer) : m_nWheel(num), m_strEngineer(engineer) {} | |
void display(Car& car); | |
private: | |
void joke(){} | |
private: | |
int m_nWheel; | |
string m_strEngineer; | |
}; | |
void Car::display(Car& car) { | |
car.joke(); | |
cout << "Car's made up:\n"; | |
cout << "Wheel number: " << car.m_nWheel << endl; | |
cout << "Engineer name: " << car.m_strEngineer << endl; | |
} | |
int main(int argc, char** argv) { | |
Car A(4, "V12"),B(6, "BMW"); | |
A.display(B); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment