Inheritance

B

bb

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.
 
B

Barry

bb said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,048
Members
47,647
Latest member
NelleMacy9

Latest Threads

Top