473,400 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

C# MC++ and "explicit implementation" for interfaces

Hi, have been searching for an answer for this for quite a while,I would be greatfull for any help.

We are developing a codebase that of components that we wouldlike to be able to write in MC++ or C# depending on thesituation. These components are accessed through a standard setof interfaces that we have defined in C#. We are using"explicit implementation" for these interfaces as thesecomponents may implement many interfaces, often with similarmethod/property names, as well as for containment.

What I would like to do is have the components appear exacly thesame from the outside, but they currently do not. The problemis that when I explicitly implement an interface in C#, themethods of the interfaces are not accessible from the classinstance (desired result). On the other hand, when I implementthe same interface in MC++, the methods are accessible from theclass instance. (would like to avoid this)

Example code:

C# component:
__________________________________________________ ________________
namespace Foo
{
public interface IBar
{
void DoStuff();
}
public class Foo : IBar
{
Foo()
{
}

void IBar.DoStuff()
{
// Do Stuff Here
}
}
}

MC++ component:
__________________________________________________ ________________
// Foo2.h
namespace Foo
{
public __gc class CFoo2 : public IBar
{
CFoo2();
void IBar::DoStuff();
}
}

// Foo2.cpp
#include "Foo2.h"

CFoo2::CFoo2()
{
}

CFoo2::IBar::DoStuff()
{
// Do Stuff here
}

C# consumer of component:
__________________________________________________ ________________
using namespace Foo;

namespace user
{
public class User
{
User()
{
// Using the C# component
Foo CSComponent = new Foo();
//CSComponent.DoStuff(); // Compiler error
((IBar)CSComponent).DoStuff(); // No problem thisworks

// Using the MC++ component
Foo2 MCppComponent = new MCppComponent();
MCppComponent.DoStuff(); // This works but Iwish it wouldn't
((IBar)MCppComponent.DoStuff(); // Add of course thisworks
}
}
}

Is it possible to get the same behaviour, or do C# and MCpp treatexplicit interface implementation differently?

As a side note, I would appreciate any recommendation for goodliterature, websites for managed C++. Through all of myresearch on the web it appears that the documentation on MC++ israther slim, whereas for C# there seems to be a wealth ofinformation.

Much appreciated,
Peter

--------------------------------
From: Peter Insley

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>21c6H3XlqEWiJaWVQUeT/A==</Id>
Nov 17 '05 #1
0 1197

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

Similar topics

7
by: lpe | last post by:
http://www.pycode.com I was kinda suprised when I could not find any good sites with 3rd party modules (other than the Vaults of Parnassus, where you must host files elsewhere), so I decided to...
6
by: wyhang | last post by:
I want a implementation just like the "join" in the unix shell, I googled the web and found nothing. Any suggestion will be highly appreciated, thank you~
3
by: Gergely Varadi | last post by:
public class A : IComparable { int IComparable.CompareTo(object obj) { return 1; } } /// <summary> /// <see cref="A.System.IComparable.CompareTo"/>
1
by: Phil Sandler | last post by:
Hello all, Thanks in advance for any help with this. I am trying to get sample code to run from Michael Russell's excellent article on removing whitespace:...
1
by: Mitan | last post by:
Hello, I'm a beginner with what appears to be a simple question for which I haven't been able to get an answer. Can someone explain what "implementation code" is in relation to VB.NET? I want to be...
8
by: kevin | last post by:
I have a form and in the form I have a sub that uses a class I instantiate using visual basic code: Public oCP As New Rs232 'instantiate the comm port I need to share this sub with...
2
by: Praveen Chandra | last post by:
Hi, I am trying to build a static library, while building the library i am getting the following error: fatal error C1189: #error : "No sstream/strstream implementation" Following is the...
5
by: Nicolas Pontoizeau | last post by:
Hi, I am handling a mixed languages text file encoded in UTF-8. Theres is mainly French, English and Asian languages. I need to detect every asian characters in order to enclose it by a special...
1
by: webtourist | last post by:
Warning: New learner here Not sure what the term means "implementation of Python". So what exactly does it mean *"implementation of Python"* like cpython, Jython, IronPython ????? In terms of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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
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
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
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
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 project—planning, coding, testing,...
0
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...

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.