M
Martin Zenkel
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;
}
};
}
------------------------
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;
}
};
}
------------------------