Thursday, 14 June 2018
virtual inhirtence
class B
{
public:
B(char c = 'a') : m_c(c) {}
public:
char get_c() const { return m_c; }
void set_c(char c) { m_c = c; }
private:
char m_c;
};
class C
: virtual public A
, public B ///Can be virutal
{ };
class D
: virtual public A
, public B //Can be Virtual
{ };
class E
: public C //Can be Virtual
, public D // Can be virtual
{ };
int main()
{
E e;
// C &c = e;
D &d = e;
C &c = e;
std::cout << c.get_c() << d.get_n();
c.set_n(3);
d.set_c('b');//d is not inherited virtually. So, it won't set it ..
std::cout << c.get_c() << d.get_n() << std::endl;// a2a3
return 0;
}
58,1 Bot
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment