Thursday, 14 June 2018

virtual Function copied the Default values from parent

#include
using namespace std;

class B
{
public:
    virtual int shift(int n = 2) const { cout<<"B"<};
class D
    : public B
{
public:
    D() {}
public:
    int shift(int n = 3) const { cout<<"D"<};
int main()
{
    const D d;
    const B *b = &d;
    std::cout << b->shift() << std::endl;   ////2<<3 16="" strong="">
    return 0;
}
                         

No comments:

Post a Comment