472,811 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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::IInterfaceB.get_Content':
overriding virtual function return type differs and is
not covariant from 'TestNamespace::ClassA::get_Content'"

Explicit implementation of "IInterfaceA.Content" 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.Content
// {
// get { return ""; }
// }

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

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

namespace TestNamespace
{

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

__property int IInterfaceB::get_Content()
{
return 0;
}

};

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

Nov 16 '05 #1
10 1673
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::get_Content(){...}" is the implementation of
the TestNamespace::::IInterfaceB.get_Content or
TestNamespace::IInterfaceA::get_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::get_Content()

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

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
"IInterfaceB", 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.Content" 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". "IInterfaceB"
declares "Content" too (assumed with completly other
meaning). "ClassB" derives from "ClassA". And it
additionally implements "IInterfaceB", 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.Content", so I think "public string Content{...}" doen't
implement the IInterfaceA.Content, it seems like a member property of the
ClassA .

If I discomment the explicit implementation code of "IInterfaceA.Content",
then I can see the "IInterfaceA.Content" 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.xxxxxx-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.Content


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.Content'." (Of course
class view tells us, that ClassA implements its
own "Content" and doesn't implement IInterfaceA.Content.
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::IInterfaceB.get_Content':
overriding virtual function return type differs and is
not covariant from 'TestNamespace::ClassA::get_Content'".
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_Content"???

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
Hello Martin,

I just got confirmation from our product group that this is a compiler
issue. It doesn't happen in Whidbey anymore because the explicit override
code underwent some changes.

The workaround is to Explicit implementation of "IInterfaceA.Content" in
ClassA avoids the compiler error, which you have found already.

Thanks very much for your feedback. If you have any more concerns on it,
please feel free to post here.

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 #11

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

Similar topics

9
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
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...
2
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...
2
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. ...
0
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...
4
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. ...
0
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)....
1
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! ...
1
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.