Inheritance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bb

    #1

    Inheritance

    struct Base {
    virtual void print() { std::cout << "** Base **" << std::endl; }
    };

    struct Deri : public Base {
    void print() { std::cout << "** Deri **" << std::endl; }
    };

    struct myInterface {
    virtual void vm(Base* bp) = 0;
    };

    struct myImpl : public myInterface {
    void vm(Deri* bp) {
    bp->print();
    }
    };

    Hi, Please could you explain why the above implementation of method
    vm() in 'myImpl' not acceptable?
    Thanks.

  • Barry

    #2
    Re: Inheritance

    bb wrote:
    struct Base {
    virtual void print() { std::cout << "** Base **" << std::endl; }
    };
    >
    struct Deri : public Base {
    void print() { std::cout << "** Deri **" << std::endl; }
    };
    >
    struct myInterface {
    virtual void vm(Base* bp) = 0;
    };
    >
    struct myImpl : public myInterface {
    void vm(Deri* bp) {
    bp->print();
    }
    };
    >
    Hi, Please could you explain why the above implementation of method
    vm() in 'myImpl' not acceptable?
    It's not "not acceptable",
    as "void myInterface::vm (Base*)" in 'myInterface' is pure virtual
    function, you have to override it to make 'myImpl' no more abstract
    before you can declare any variable of 'myImpl'.

    Actually, here
    "void myImpl::vm(Deri *)"
    is not overriding "void myInterface::vm (Base*)", as they have different
    parameter lists.


    --
    Thanks
    Barry

    Comment

    Working...