473,490 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
Create 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 1196
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::Object ^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********@discussions.microsoft.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::Object ^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
4614
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
13781
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...
4
2835
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. ...
6
1919
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...
8
3918
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...
1
2431
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...
15
2766
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....
52
20810
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...
114
3788
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...
0
7112
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,...
0
6974
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...
0
7146
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,...
0
7183
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...
0
7356
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...
0
5448
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,...
0
4573
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...
0
1389
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 ...
0
277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.