polymorphism - Does a member of a C++ base class really needs to be virtual to be overridden by a derived class? -



polymorphism - Does a member of a C++ base class really needs to be virtual to be overridden by a derived class? -

class { public: virtual int test()=0; }; class b : public { public: int test(){return 10;} }; b *b = new b(); b->test(); // homecoming 10;

whereas:

class { public: int test(){return 0;} }; class b : public { public: int test(){return 10;} }; b *b = new b(); b->test(); // **would homecoming 0**;

why homecoming "0" here? makes 0 sense me, because assume (kind of overloaded) members of derived class (b) come first! happening here?

apart invalid syntax (b->test(); should b->test();), sec 1 homecoming 10.

if instead have written:

a* = new b(); a->test();

it have returned 0 or 10 depending on whether a::test virtual.

c++ polymorphism virtual members

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -