473,545 Members | 2,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Interface implementation

Hi all. I have some questions about interface implementation, if
anybody can help me, I will be very thank.
So:

If i have some interface IA:

class IA
{
virtual void SomePureVirtFun c() = 0;
};

and some class B, that implemented that interface:

class B : public IA
{
virtual void SomePureVirtFun c() {};
};

Now I need in class C inherit from interface ITwoInOne, that inherited
from IA also.
Question: it is any method, inherit from interface ITwoInOne, and
don't implement interface IA, but using multiple inheritance - inherit
from class B, that already implemented that interface, and satisfy my
requirements?

Another words: can I write something like that:

class NewOne : public B
, public ITwoInOne
{
//Implementation only pure virtual functions
//, that not correspond to IA interface
}

P.S. sorry for confusion, and for my bad English.

Jun 14 '07 #1
17 1805
Galian wrote:
Hi all. I have some questions about interface implementation, if
anybody can help me, I will be very thank.
So:

If i have some interface IA:

class IA
{
virtual void SomePureVirtFun c() = 0;
};

and some class B, that implemented that interface:

class B : public IA
{
virtual void SomePureVirtFun c() {};
};

Now I need in class C inherit from interface ITwoInOne, that inherited
from IA also.
Question: it is any method, inherit from interface ITwoInOne, and
don't implement interface IA, but using multiple inheritance - inherit
from class B, that already implemented that interface, and satisfy my
requirements?
Yes, inherit from IA _virtually_ *everywhere*. I.e. make B inherit from
IA virtually and make ITwoInOne inherit virtually.
>
Another words: can I write something like that:

class NewOne : public B
, public ITwoInOne
{
//Implementation only pure virtual functions
//, that not correspond to IA interface
}

P.S. sorry for confusion, and for my bad English.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 14 '07 #2
Yes, inherit from IA _virtually_ *everywhere*. I.e. make B inherit from
IA virtually and make ITwoInOne inherit virtually.
So this is right way:

class B : public virtual IA
{

};

class NewOne : public virtual B
, public virtual ITwoInOne
{

};

Is this right?
If yes, than question: is order of classes for inheritance important?
I mean it is OK if I write first "public virtual ITwoInOne", and than
"public virtual B"?

Jun 14 '07 #3
Galian wrote:
>Yes, inherit from IA _virtually_ *everywhere*. I.e. make B inherit
from IA virtually and make ITwoInOne inherit virtually.

So this is right way:

class B : public virtual IA
{

};

class NewOne : public virtual B
, public virtual ITwoInOne
{

};

Is this right?
If yes, than question: is order of classes for inheritance important?
I mean it is OK if I write first "public virtual ITwoInOne", and than
"public virtual B"?
I think that the order is not significant. Have you tried it? If you
have, and the success depended on the order, could you please share?
If you haven't tried, why?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 14 '07 #4
I have tried, and it don't work. "Cannot instantiate abstract class"
error. I don't now why. I tried different order, but it don't help.
Thank you Victor for the answers.

Jun 14 '07 #5
Galian wrote:
I have tried, and it don't work. "Cannot instantiate abstract class"
error. I don't now why. I tried different order, but it don't help.
Sounds like FAQ 5.8 should help. Check it out. It also can be that
your compiler is not capable; we'll know as you check out the FAQ.
Thank you Victor for the answers.
You're most welcome.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 14 '07 #6

Victor Bazarov :
Galian wrote:
I have tried, and it don't work. "Cannot instantiate abstract class"
error. I don't now why. I tried different order, but it don't help.

Sounds like FAQ 5.8 should help. Check it out. It also can be that
your compiler is not capable; we'll know as you check out the FAQ.
Thank you Victor for the answers.

You're most welcome.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sorry Victor, but about what FAQ you talking? Where can I find it?

Jun 14 '07 #7
Galian wrote:
Victor Bazarov :
>Galian wrote:
>>I have tried, and it don't work. "Cannot instantiate abstract class"
error. I don't now why. I tried different order, but it don't help.
Sounds like FAQ 5.8 should help. Check it out. It also can be that
your compiler is not capable; we'll know as you check out the FAQ.

Sorry Victor, but about what FAQ you talking? Where can I find it?
C++ FAQ: http://www.parashift.com/c++-faq-lite
FAQ 5.8: http://www.parashift.com/c++-faq-lit...t.html#faq-5.8
Jun 14 '07 #8
Galian wrote:
Victor Bazarov :
>[..] check out the FAQ.
[..]
Sorry Victor, but about what FAQ you talking? Where can I find it?
Is that your first day here?

http://www.parashift.com/c++-faq-lite/

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 14 '07 #9
Sorry Victor, but about what FAQ you talking? Where can I find it?

Wow, I understand :) sorry.

This is my code. Task is next: I want write template class, CUnknown,
with implemented nessesary methods (Queryinterface , Release ...), to
use it for other classes.

CUnknown:

template < class ClassType, REFIID ObjectIID >
class CUnknown : public IUnknown
{
protected:
// IUnknown methods.
virtual STDMETHODIMP QueryInterface( REFIID riid, void** ppv )
{
if ( ppv == NULL )
{
return E_POINTER;
}
if ( riid == *ObjectIID || riid == IID_IUnknown )
{
*ppv = static_cast< ClassType* >( this );
AddRef();
return S_OK;
}
*ppv = NULL;
return E_NOINTERFACE;
}

virtual STDMETHODIMP_( ULONG ) AddRef()
{
return InterlockedIncr ement( &m_cRef );
}

virtual STDMETHODIMP_( ULONG ) Release()
{
LSCOPE( "CMediaBuffer:: Release" );
LONG lRef = InterlockedDecr ement( &m_cRef );
if ( lRef == 0 )
{
delete this;

// m_cRef is no longer valid! Return lRef.
}
return lRef;
}

LONG m_cRef;
};

#include "Unknown.h"

class ISMSNotificatio nHandler
{
public:
virtual void HandleSMSMessag eReceived( const CEOID messageID ) = 0;
};

// IMAPIAdviseSink also derived from IUnknown

class CAdviseSinc
// This is my CUnknown,but anyway "Cannot instantiate abstract
class" error
: public virtual CUnknown< CAdviseSinc, IID_IMAPIAdvise Sink >
, public virtual IMAPIAdviseSink
{
public:
CAdviseSinc();
~CAdviseSinc();

private:
ULONG OnNotify( ULONG cNotif, LPNOTIFICATION lpNotifications );
};
>>Is that your first day here?
Actually in this group yes, but not in other, I am sorry.

Jun 14 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4625
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
3
2359
by: Sai Kit Tong | last post by:
I posted for help on legacy code interface 2 days ago. Probably I didn't make it clear in my original mail. I got a couple of answers but none of them address my issues directly (See attached response). My first reply directed me to source code migration but I didn't have the source code. The second reply mentioned about .NET interoperability...
3
330
by: John Underwood | last post by:
Hi.. I was looking at interface, and I have a example in the docs i'll paste below.. I'm not grasping what you would gain by using a interface, does any one have a brief description of their benefit? Thanks, John Underwood
21
13790
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered by Sets. - ICollection cannot decide containment - IList promises indexability by the natural numbers, which is not achievable (since i hash...
15
12770
by: jon | last post by:
How can I call a base interface method? class ThirdPartyClass :IDisposable { //I can not modify this class void IDisposable.Dispose() { Console.WriteLine( "ThirdPartyClass Dispose" ); } } class MyClass :ThirdPartyClass, IDisposable { void IDisposable.Dispose() {
4
2839
by: Ray Dukes | last post by:
What I am looking to do is map the implementation of interface properties and functions to an inherited method of the base class. Please see below. '**************************************************************************** ' Issues '****************************************************************************
6
1929
by: Ricky W. Hunt | last post by:
It's dawning on my a lot of my problems with VB.NET is I'm still approaching it in the same way I've programmed since the late 70's. I've always been very structured, flow-charted everything, used subroutines, etc. Now I'm trying to study this new way and I'm getting some terms confused and can find no clear definition (some even overlap or...
8
3932
by: Gregory | last post by:
I have a question about using STL containers in C++ class public interface. Lets say that I want to return some container from class method or accept class method parameter as some container. For example: class A { public: const vector<int>& getTable() { return m_table; }
15
2774
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interface”. In a functional language, a function can be specified by its name and parameter specs. For example: f(3) f(3, )
52
20830
by: Ben Voigt [C++ MVP] | last post by:
I get C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27): error CS0535: 'UselessJunkForDissassembly.InvocableInternals' does not implement interface member 'UselessJunkForDissassembly.IInvocableInternals.OperationValidate(string)' C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27): error CS0535:...
0
7496
marktang
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, well explore What is ONU, What Is Router, ONU & Routers main...
0
7428
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...
0
7685
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7784
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6014
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5071
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...
0
3485
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...
1
1916
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
1
1039
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.