Hasani said:
How would u implement the following in c++
[SNIP]
so here you have 2 interfaces with signatures that only differ by return
type. If I wanted to make a clas FooBar in c++ that implements/inherits
both interfaces, how would I go about doing this. Please provide a code
example as you did b4 but using synatax that will compile in c++.net
7.0/7.1 (no ^, ref, etc).
First, this is one place where the new syntax is superior to the old syntax.
You will have better reliability that the compiler can do the right thing in
the new syntax. I'll present both the old and new syntax for completeness.
Here is the new syntax:
using namespace System;
public interface class IFoo {
int GetValue();
};
public interface class IBar {
String^ GetValue();
};
public ref class R : IFoo, IBar {
public:
virtual int G1() = IFoo::GetValue;
virtual String^ G2() = IBar::GetValue;
};
int R::G1() { return 42; }
String^ R::G2() { return "Hello World!"; }
int main() {
R^ r = gcnew R;
IFoo^ f = r;
IBar^ b = r;
Console::WriteLine(f->GetValue());
Console::WriteLine(b->GetValue());
}
And here is the old syntax:
#using <mscorlib.dll>
using namespace System;
public __gc __interface IFoo {
int GetValue();
};
public __gc __interface IBar {
String* GetValue();
};
public __gc class R : public IFoo, public IBar {
public:
virtual int IFoo::GetValue();
virtual String* IBar::GetValue();
};
int R::IFoo::GetValue() { return 42; }
String* R::IBar::GetValue() { return S"Hello World!"; }
int main() {
R* r = new R;
IFoo* f = r;
IBar* b = r;
Console::WriteLine(f->GetValue());
Console::WriteLine(b->GetValue());
}