关于虚函数多重继承

class component
{
public:
virtual void print()const = 0;
};

class composite :public component
{
component* m_child;
public:
void setChild(component* child)
{
m_child = child;
}
virtual void print()const{ cout << "composite" << endl; }
};

class leaf :public component
{
public:
void print()const { cout <<" leaf Node "<< endl; }
};

 

void _tmain()
{
leaf node;
composite comp;
comp.setChild(&node);
component* p = &comp;
p->print();
}

posted @ 2016-05-09 08:45  huninglei  阅读(196)  评论(0编辑  收藏  举报