Connecting Tech Pros Worldwide Help | Site Map

Inheritance

bb
Guest
 
Posts: n/a
#1: Sep 25 '07
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
Guest
 
Posts: n/a
#2: Sep 25 '07

re: Inheritance


bb wrote:
Quote:
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
Closed Thread