# Kisser Leon

posts - 100, comments - 102, trackbacks - 0, articles - 0

output信息：
///////////////////////////////
AD:BE
BE:A //如果正确的话，这里应该输出BE:AD
AD:B
B:A  //如果正确的话，这里应该输出B:AD

AD:BE
BE:A
A:B
B:A

///////////////////////////////

error: invalid conversion from `A*' to `AD*'
///////////////////////////////

AD:BE
BE:AD
AD:B
B:AD

AD:BE
BE:A
A:B
B:A
///////////////////////////////

over。

////////////////////////////////////
#include <iostream>
#include <list>
using namespace std;

class A;
class AD;
//B
class B
{
public:
void virtual output(A * a){cout << "B:A" << endl;}
void virtual output(AD * ad){cout << "B:AD" << endl;}
};
class BE : public B
{
public:
void output(A * a){cout << "BE:A" << endl;}
void output(AD * ad){cout << "BE:AD" << endl;}
};

//A
class A
{
public:
void virtual output(B * b, A * a){cout << "A:B" << endl;b->output(a);}
void virtual output(BE * b, A * a){cout << "A:BE" << endl;b->output(a);}
};
class AD : public A
{
public:
void output(B * b, A * a){cout << "AD:B" << endl;b->output(a);}
void output(BE * b, A * a){cout << "AD:BE" << endl;b->output(a);}
};

int main()
{
A * pAD = new AD;
pAD->output(new BE, pAD);
pAD->output(new B, pAD);

cout<<endl;

A * pA = new A;
pA->output(new BE, pA);
pA->output(new B, pA);

return 0;
}

### Feedback

class BE : public B
{
public:
void output(A * a){cout << "BE:A" << endl;}
void output(AD * ad){cout << "BE:AD" << endl;}
};

 只有注册用户登录后才能发表评论。 【推荐】100%开源！大型工业跨平台软件C++源码提供，建模，组态！ 相关文章: