Connecting Tech Pros Worldwide Help | Site Map

Inheritance

  #1  
Old September 25th, 2007, 04:45 PM
bb
Guest
 
Posts: n/a
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.

  #2  
Old September 25th, 2007, 04:55 PM
Barry
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
inheritance is not for code-reuse (??) Bart Simpson answers 6 May 6th, 2007 06:05 PM
why C# can't support multiple inheritance? Matthew Louden answers 22 November 15th, 2005 05:48 PM
Virtual inheritance... JKop answers 4 July 22nd, 2005 10:27 PM
Multiple inheritance performance hit Graham Banks answers 2 July 19th, 2005 05:03 PM
Error in msvc in building inheritance.obj to build hello.pyd AIM answers 2 July 18th, 2005 07:38 PM