473,623 Members | 2,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Independent interface implementation

Hi,

sorry for this C++ noob question... I'm coming from VB.Net actually and I
am trying to do the same in C++ (/CLR) as I do here (pseudo code partial):

class C
implements I1
implements I2

private sub I1_f1() implements I1.f1
end sub

private sub I2_f1(args) implements I2.f1
end sub

public sub M1
end sub
public sub M2()
end sub
end class

So, in VB.Net it is possible to write an object that has 3 different
(inter)faces:

a) class ("Dim o As C"): public methods M1, M2
b) implementing interface I1 ("Dim o as I1 = New C"): method f1 implemented
by I1_f1
c) implementing interface I2 ("Dim o as I2 = New C"): method f1 implemented
by I2_f1

For me it is especially very important to consider each of the three as an
independent and individual context. A reference of type C is a different
context(/contract) than a reference of type I1 or than type I2, even if all
references reference the same object.

I haven't figured out how to realize the same in C++. It seems, the "wiring"
of interface members to class members is only done by the member name. As a
consequence, the independence is lost. Therefore, I don't know how to write
different implementations for function f1 that only happens to have the same
name in both interfaces but might have a completely different meaning. I
also don't know how to avoid that a function implementing an interface is
added to the "class interface" (a reference of type C).

I hope you can help me with this or just tell me that it is not possible.

Thanks in advance.
Armin

Oct 6 '08 #1
3 1205
Armin Zingler wrote:
Hi,

sorry for this C++ noob question... I'm coming from VB.Net actually and I
am trying to do the same in C++ (/CLR) as I do here (pseudo code partial):
I could be making this up, but I think the following is correct:

class C : public I1, I2
{
private:
I1::f1()
{
...
}

I2::f1()
{
...
}
};
A useful resource for getting started with C++/CLI:
http://www.functionx.com/cppcli/index.htm

Adelle.
Oct 7 '08 #2
This is the equivalent produced by Instant C++ - note that the method name
does not have to be the same as the interface name if you use the explicit
CLI implementing syntax (e.g., "sealed = I1::f1"):

private ref class C : I1, I2
{

private:
virtual void I1_f1() sealed = I1::f1
{
}

virtual void I2_f1(System::O bject ^args) sealed = I2::f1
{
}

public:
void M1()
{
}
void M2()
{
}
};
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB & C# to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI
"Armin Zingler" wrote:
Hi,

sorry for this C++ noob question... I'm coming from VB.Net actually and I
am trying to do the same in C++ (/CLR) as I do here (pseudo code partial):

class C
implements I1
implements I2

private sub I1_f1() implements I1.f1
end sub

private sub I2_f1(args) implements I2.f1
end sub

public sub M1
end sub
public sub M2()
end sub
end class

So, in VB.Net it is possible to write an object that has 3 different
(inter)faces:

a) class ("Dim o As C"): public methods M1, M2
b) implementing interface I1 ("Dim o as I1 = New C"): method f1 implemented
by I1_f1
c) implementing interface I2 ("Dim o as I2 = New C"): method f1 implemented
by I2_f1

For me it is especially very important to consider each of the three as an
independent and individual context. A reference of type C is a different
context(/contract) than a reference of type I1 or than type I2, even if all
references reference the same object.

I haven't figured out how to realize the same in C++. It seems, the "wiring"
of interface members to class members is only done by the member name. As a
consequence, the independence is lost. Therefore, I don't know how to write
different implementations for function f1 that only happens to have the same
name in both interfaces but might have a completely different meaning. I
also don't know how to avoid that a function implementing an interface is
added to the "class interface" (a reference of type C).

I hope you can help me with this or just tell me that it is not possible.

Thanks in advance.
Armin

Oct 7 '08 #3
"David Anton" <Da********@dis cussions.micros oft.comschrieb
This is the equivalent produced by Instant C++ - note that the
method name does not have to be the same as the interface name if
you use the explicit CLI implementing syntax (e.g., "sealed =
I1::f1"):

private ref class C : I1, I2
{

private:
virtual void I1_f1() sealed = I1::f1
{
}

virtual void I2_f1(System::O bject ^args) sealed = I2::f1
{
}

public:
void M1()
{
}
void M2()
{
}
};


Aaah! :-) Thanks a lot for this. Also thanks to Adelle. Don't know why I
missed the decisive part. (thought I've read the language reference
thoroughly...). I'll clean my glasses next time before....

Now knowing what to look for, if anybody will search the archives, here's
the link:
http://msdn.microsoft.com/en-us/library/fw0bbh51.aspx
Armin

Oct 7 '08 #4

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

Similar topics

9
4634
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
21
13816
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 elements, not sort them). - IDictionary is definatly not setlike. Although I can, of course, define...
4
2843
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
1935
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 use two different words for the same thing, even when they are actually different). I'm reading a...
8
3943
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; }
1
2443
by: /M | last post by:
Hi! As you know, one way to seperate platform dependent code from platform _independent_ code is to create an abstract base class which acts as an interface towards all platform independent code and implement platform specific code in the sub classes. Since the platform (in most cases I quess :) ) can't vary during the execution of a program, using virtual functions to specify the interface seams a bit odd. I'm thinking about using...
15
2782
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
20860
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: 'UselessJunkForDissassembly.InvocableInternals' does not implement interface member...
114
3841
by: Andy | last post by:
Dear Python dev community, I'm CTO at a small software company that makes music visualization software (you can check us out at www.soundspectrum.com). About two years ago we went with decision to use embedded python in a couple of our new products, given all the great things about python. We were close to using lua but for various reasons we decided to go with python. However, over the last two years, there's been one area of grief...
0
8160
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,...
0
8661
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8603
jinu1996
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...
1
8312
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,...
0
8460
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6104
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5559
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();...
0
4153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1766
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.