473,848 Members | 1,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Explicit interface implementation compiler bug in VS 2003?

Assumed two assemblies (one C# and one C++), C++ refers
to C#. The follwing code compiles and works well under VS
2002! VS 2003 C++ compiler reports the error

"error
2555: 'TestNamespace: :ClassB::IInter faceB.get_Conte nt':
overriding virtual function return type differs and is
not covariant from 'TestNamespace: :ClassA::get_Co ntent'"

Explicit implementation of "IInterfaceA.Co ntent" in
ClassA avoids the compiler error.

Two questions:
Why does this error occur in C++ (and with C# not)?
Why does explicit implementation "solve" the problem?
content of C# assembly:
-----------------------
using System;

namespace TestNamespace
{
public interface IInterfaceA
{
string Content
{
get;
}
}

public interface IInterfaceB
{
int Content
{
get;
}
}
public class ClassA : IInterfaceA
{

// string IInterfaceA.Con tent
// {
// get { return ""; }
// }

public string Content
{
get { return ""; }
}
}

public class ClassC : ClassA, IInterfaceB
{
int IInterfaceB.Con tent
{
get { return 0; }
}
}
}
------------------------
content of C++ assembly:
------------------------
#pragma once

namespace TestNamespace
{

public __gc class ClassB : public ClassA, public
IInterfaceB
{
public:

__property int IInterfaceB::ge t_Content()
{
return 0;
}

};

}
------------------------

Nov 16 '05 #1
10 1725
HI Martin,

Thanks for posting in the group!

If you have looked up the documentation of the error C2555 on MSDN, you
could find the following explanation:
"A virtual function and a derived overriding function have identical
parameter lists but different return types. An overriding function in a
derived class cannot differ from a virtual function in a base class only by
its return type."

So in your situation, the VC++ 7.1 compiler cannot determine whether the
"__property int IInterfaceB::ge t_Content(){... }" is the implementation of
the TestNamespace:: ::IInterfaceB.g et_Content or
TestNamespace:: IInterfaceA::ge t_Content, they have the same function name
and without parameter, only different from the return type.

BTW, I am not familiar with the C#, but I think in C# an overriding
function in a derived class can differ from a virtual function in a base
class only by its return type.
Best regards,
Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

Nov 16 '05 #2
Hello Gary,

thank you for your reply.

I understand the error message of the c++ compiler
completely. But it should not occur, because using the
line

__property int IInterfaceB::ge t_Content()

in ClassB I stated clearly that I want to implement the
property "Content" of the interface "IInterface B".

The c++ compiler of VS 2002 was able to understand this
as well as the c# compiler (see implementation of ClassC).

The most strange thing is if i implement the "Content"
property of "IIntefaceA " in ClassA explicitly then the
c++ compiler reports no error although the functions
which have caused the error are still there.

Nov 16 '05 #3
Hi Martin,

Thanks for your quickly response!

From my point of view, if you implement the "Content" property of
"IIntefaceA " in ClassA explicitly, the compiler can fit your implementation
of the property "Content" (in VC assembly) only to interface
"IInterface B", for the reason that "Content" property of "IIntefaceA "
already have a explicit implementation.

I noticed something deferent in the Class View Tab when you explicit
implementation of "IInterfaceA.Co ntent" in ClassA (C# Assembly).
Best regards,
Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

Nov 16 '05 #4
Hi Gary,

Thanks again for your reply!
From my point of view, if you implement the "Content" property of"IIntefaceA " in ClassA explicitly, the compiler can fit your implementationof the property "Content" (in VC assembly) only to interface"IInterfaceB ", for the reason that "Content" property of "IIntefaceA "already have a explicit implementation.


This is true of course. This fact is quite simple to
understand. But unfortunately this is not an answer to
the question of this thread.
Let me put the leading question into other words:
"ClassA" declares and implements "Content". "IInterface B"
declares "Content" too (assumed with completly other
meaning). "ClassB" derives from "ClassA". And it
additionally implements "IInterface B", which means to
implement "Content". Why is this not possible in C++?

Further question: Can you (as MS-partner) try to compile
this code using the current Whidbey alpha version?

Best regards,
Martin Zenkel

Nov 16 '05 #5
Hi Martin,

Thanks for your reply!
"ClassA" declares and implements "Content"

In the class view tab, I can see the "Content" entry , not the
"IInterfaceA.Co ntent", so I think "public string Content{...}" doen't
implement the IInterfaceA.Con tent, it seems like a member property of the
ClassA .

If I discomment the explicit implementation code of "IInterfaceA.Co ntent",
then I can see the "IInterfaceA.Co ntent" entry appears. This is what I want
to express in my last post.

For compile the code in Whidbey alpha version, I will reply you the result
in a few days.

Best regards,
Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

Nov 16 '05 #6
Hi Martin,

I have test your sample code in the current Whidbey Beta
version(m2.xxxx xx-xxxx), and under this new version, it has been compiled
with no error occurring.

Best regards,
Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

Nov 16 '05 #7
Hi Gary,

Thanks again for your quick reply!
...I think "public string Content{...}" doen't
implement the IInterfaceA.Con tent


1.) Assuming you (and the class view) are right:
In this case I am very surprised NOT to get the compiler
error "error CS0536: 'TestNamespace. ClassA' does not
implement interface
member 'TestNamespace. IInterfaceA.Con tent'." (Of course
class view tells us, that ClassA implements its
own "Content" and doesn't implement IInterfaceA.Con tent.
IMHO class view and compiler information are not
consistent concerning this point. In the end there is no
other option than trustng the compiler, which produces
our runtime code.)

But strictly speaking our initial question hasn't as much
to do with ClassA rather than ClassB.

2.) Again with other words, the original question to our
example:
We get the compiler error "error
C2555: 'TestNamespace: :ClassB::IInter faceB.get_Conte nt':
overriding virtual function return type differs and is
not covariant from 'TestNamespace: :ClassA::get_Co ntent'".
In ClassB we declare that ("IInterfaceB!! !::get_Content" )
is what we are going to implement. Why is the compiler
still "thinking" that we want to
override "ClassA::get_Co ntent"???

Apart from this:
It WORKS with the previous version (VS2002). It WORKS
with the next version (Whidbey Beta, thank you for
testing). It DOESN'T WORK with the current version
(VS2003)!

Best regards,
Martin Zenkel
Nov 16 '05 #8
Hi Gary,
I have test your sample code in the current Whidbey Beta


Thank you very much.

Best regards, Martin Zenkel
Nov 16 '05 #9
Hi Martin,

I will look into it and contact our product group to see if we could get
more information on it. I will post back as soon as possible.

Thanks very much.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 16 '05 #10

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

Similar topics

9
4661
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
12
2818
by: Steve W. | last post by:
I just read the section (and did the exercise) in the C# Step by Step book that covers Explict Interface Implementation (where you specify in the method implementation the specific interface that you are implementing in the class. Other than to resolve the problem that arises when a class implements two interfaces with the same method signature, what good is it?
2
3455
by: Todd Brooks | last post by:
I have a coclass that implements a dual interface. The thing that's a little unusual is that the coclass doesn't inherit directly from the interface, rather it inherits from an implementation class that inherits from the interface. This means that by default the attribute code generator doesn't pick up the interface. According to the docs, I should be able to use the implements() attribute to tell the compiler that the coclass implements...
2
2518
by: COLIN JACK | last post by:
Hi All, I've got a situation where I'm implementing an interface (BaseInterface in example below) and I want to use explicity interface implementation of an event so that I can add type safety. To see what I mean look at the example below where the class implementing the interface actually wants the event to be for a more specific delegate. Now this seems to work but the code, to me is unnecessarily ugly. This leaves me wondering if...
0
1218
by: Peter Insley via .NET 247 | last post by:
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...
4
2863
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 '****************************************************************************
0
2225
by: Ken | last post by:
Hi I have a little application that does datavalidation. It supports dynamically loaded plugins (you drop a dll with a class implementing IValidator<Tin the same dir as the main application). All classes that implement this interface are shown in a drop down in a DataGridViewComboBoxColumn named Validator. By choosing the class to validate this specific data in the drop downbox IValidator<T>.Validate is called and returns true/false....
1
2765
by: recherche | last post by:
Hola! I tried the following public implementation of interface indexer by struct (Code Snippet 1) in private and explicit implementation by struct (Code Snippet 2) but in vain. Please help! Code Snippet 1:
1
3227
by: =?Utf-8?B?Sk0=?= | last post by:
In an application I have an interface with methods and properties. The interface is used on a Class (ie class MyClass : IMyClassA, IMyClassB). On a windows form I define a BindingSource (_bindingMyClass) where I set the DataSource property to the interface IMyClass. Now when the MyClass object is instantiated I set the BindingSource to the instance of the IMyClass interface (_MyClass) _bindingMyClass.DataSource = this._MyClass;
0
10661
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...
0
10347
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...
0
9497
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7889
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
7067
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
5731
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5917
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4134
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3172
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.