public 用 + 表示
protected 用 # 表示
private 用 - 表示
class Person
{
public:
void setName(std::string name) {
this->name = name;
}
std::string getName() {
return this->name;
}
public:
int nationality;//国籍
protected:
int idCard;//身份证号
private:
std::string name;//姓名
};
class QQZone
{
};
class QQNumber
{
QQZone zone;
};
class Water;
class Climate
{
Water* m_water;
};
class Water
{
Climate* m_climate;
};
class Wings {};
class Goose
{
public:
Goose() {
m_wings = new Wings;//组合关系
}
private:
Wings* m_wings;
};
class Wings {};
class Goose
{
public:
Goose(Wings* pWings):m_wings(pWings){//聚合关系
}
private:
Wings* m_wings;
};
1、Water作为Animal类某个方法中的局部变量
2、Water作为全局类,Animal直接调用Water类
3、Water类作为Animal类某个方法中参数或者返回值
class Water
{
};
class Animal
{
void Drink()
{
//注意:持有Water类的是Drink方法,而不是Animal类。Drink被调用时Water类才被实例化
//2、 的例子
Water *water = new Water;
}
};
class Car
{
};
class Jeep: public Car
{
};
class Interface_A {
public:
virtual void test() = 0;
};
class Class_A
{
public:
void test() {
}
};