Hi,
I've got a question regarding class inheritance. The following code
reproduces the problem I'm dealing with:
class IBase
{
public:
virtual void Method(void)=0;
};
class IDefinition : public IBase
{
};
class CCoImpl
{
public:
void Method(void){}
};
class CImpl : public IDefinition, public CCoImpl
{
};
In the above 4 classes, IBase and IDefinition are both abstract classes.
CCoImpl contains a non-virtual method (actual implementation) . CImpl is
derived from both IDefinition and CCoImpl. But when I try to initiate a new
instance of CImpl, the compiler complains about that CImpl is an abstract
class because void IBase::Method(v oid); isn't defined.
Why is that? CImpl is derived from CCoImpl, doesn't it inherit the "void
Method(void);" method from CCoImpl? If it does, this method should be
implemented and CImpl shouldn't be an abstract class.
Given that IBase and IDefinition can't be changed, how do I create a CImpl
class that uses the "Method(voi d);" implementation from CCoImpl?
Thanks,
--
He Shiming 2 1491
He Shiming wrote: I've got a question regarding class inheritance. The following code reproduces the problem I'm dealing with:
class IBase { public: virtual void Method(void)=0; };
class IDefinition : public IBase { };
class CCoImpl { public: void Method(void){} };
class CImpl : public IDefinition, public CCoImpl {
Add here
void Method() { CCoImpl::Method (); }
};
In the above 4 classes, IBase and IDefinition are both abstract classes. CCoImpl contains a non-virtual method (actual implementation) . CImpl is derived from both IDefinition and CCoImpl. But when I try to initiate a new instance of CImpl, the compiler complains about that CImpl is an abstract class because void IBase::Method(v oid); isn't defined.
Right. It isn't.
Why is that? CImpl is derived from CCoImpl, doesn't it inherit the "void Method(void);" method from CCoImpl?
Inherit, yes. But 'CCoImpl::Metho d' isn't virtual. If it isn't virtual,
it cannot be an overrider, can it?
If it does, this method should be implemented and CImpl shouldn't be an abstract class.
Nope. That's not how overriding works.
Given that IBase and IDefinition can't be changed, how do I create a CImpl class that uses the "Method(voi d);" implementation from CCoImpl?
See above.
V
"He Shiming" <mailbill(NOSPA M)@21cn.com.nos pam> wrote in message
news:d8******** **@news.yaako.c om... Hi,
I've got a question regarding class inheritance. The following code reproduces the problem I'm dealing with:
class IBase { public: virtual void Method(void)=0; };
class IDefinition : public IBase { };
class CCoImpl { public: void Method(void){} };
class CImpl : public IDefinition, public CCoImpl { };
In the above 4 classes, IBase and IDefinition are both abstract classes. CCoImpl contains a non-virtual method (actual implementation) . CImpl is derived from both IDefinition and CCoImpl. But when I try to initiate a new instance of CImpl, the compiler complains about that CImpl is an abstract class because void IBase::Method(v oid); isn't defined.
Why is that? CImpl is derived from CCoImpl, doesn't it inherit the "void Method(void);" method from CCoImpl? If it does, this method should be implemented and CImpl shouldn't be an abstract class.
In the current situation you have name collision between IDefinition::Me thod
and CCoImpl::Method .
CCompl::Method cannot hide the abstract one as there is no inheritance
relation between the IDefinition and CCoImpl classes. To resolve this issue
you need corresponding Method function defined explicitly in the CImpl
class:
class CImpl : public IDefinition, public CCoImpl
{
public:
void Method(void)
{
CCoImpl::Method ();
}
};
Regards,
Janusz This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: darkstorm |
last post by:
I have a doubt regarding inheritance involving templates
Consider this:
/////////////////////////////////////
template<typename T>
class A
{
private:
T m_a;
|
by: He Shiming |
last post by:
Hi,
I've got a question regarding class inheritance. The following code
reproduces the problem I'm dealing with:
class IBase
{
public:
virtual void Method(void)=0;
};
|
by: JKJ |
last post by:
I'm not an OOP guru, but I would say ". . .not necessarily"
What if the base class and derived classes are internal?
Then the base class has to be within the same assembly to
be inherited from. You may want to create several classes
that are used throughout the assembly, but are not
accessible outside the assembly. . .
If your base class will be inherited across multiple
assemblies and future applications, then I would then
|
by: Peter Oliphant |
last post by:
I just discovered that the ImageList class can't be inherited. Why? What
could go wrong? I can invision a case where someone would like to add, say,
an ID field to an ImageList, possible so that the individual elements in an
array of ImageList's could be identified by the ID, thereby allowing
re-ordering the array without harm. A person could identify by index into
the array, but that would not be preserved by re-ordering (and re-ordering...
|
by: ^MisterJingo^ |
last post by:
Hi all,
I have a question regarding inheritance. I'll use the following code
for an example (its been stripped down to the minimum):
// code start
using System;
class Animal
{
| |
by: et |
last post by:
I am new to asp.net. I am writing a program that will revolve around an
extensive client database, and wonder what the best way to design the
program is, using classes. I have about 10 different sections, or
categories if you will, about a client. For instance, some clients have
data regarding our Estate Planning section, some clients have data regarding
our Real Estate section, etc. Would it be better to have one object that...
|
by: Pravesh |
last post by:
Hello All,
I had some query regarding virtual functions/destructors. If a class is
having some/all of its methods that are virtual then is it recommended
that it should also have virtual destructor?
When I am defining such a class with default destructor then my
compiler is giving warning that class XXX has virtual functions but
non-virtual destructor.
|
by: RSH |
last post by:
I have a simple question regarding inheritance in a web form.
I have a DropDownList in an aspx form. It is called DropDownList1
I have a class that will be overriding the render event so I have a snippet
of this class:
Public Class CustomDDL
Inherits DropDownList
|
by: Oskar Bennet |
last post by:
Hi everybody,
I am supposed to draw a simple UML diagram for a very small project that
consists of less than a dozen classes. I have never been working with
UML before, I have read some tutorials but I cannot find the connection
between UML and my C++ code.
What I have found out so far is that inheritance is indicated by an
arrow like this
|\
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |