Connecting Tech Pros Worldwide Help | Site Map

Inheritance

 
LinkBack Thread Tools Search this Thread
  #1  
Old September 25th, 2007, 03:45 PM
bb
Guest
 
Posts: n/a
Default 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.


  #2  
Old September 25th, 2007, 03:55 PM
Barry
Guest
 
Posts: n/a
Default 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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.