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 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.
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
"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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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: 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.
...
|
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...
|
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...
| |
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...
|
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....
|
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...
|
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...
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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,...
|
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...
|
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 ...
| |
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...
| |