所有的笔记是在学习solo learn的C++的过程中所写下来的。地址:https://www.sololearn.com/Play/CPlusPlus
现在在学习类的Composition(复合),现在有这样的一个例子
#include <iostream>
using namespace std;
class Birthday {
public:
Birthday(int m, int d, int y)
: month(m), day(d), year(y)
{ }
void printDate()
{
cout<<month<<"/"<<day <<"/"<<year<<endl;
}
private:
int month;
int day;
int year;
};
class Person {
public:
Person(string n, Birthday b)
: name(n), bd(b)
{ }
void printInfo()
{
cout << name << endl;
bd.printDate();
}
private:
string name;
Birthday bd;
};
int main() {
Birthday bd(2, 21, 1985);
P