如何在VC++/CLI中实现VB.net中定义的接口?
How to implement an interface defined in VB.net in VC++/CLI?
我有一个基于 VB.net 的界面,如下所示:
Namespace Foo
Public Interface Bar
ReadOnly Property Quuxes as Quux()
End Interface
End Namespace
我现在想在 VC++/CLI 中实现它(因为我需要从非托管 third-party DLL 接口函数),但是我无法弄清楚如何实现的正确语法它。
这是我目前拥有的 header 文件的相关部分:
namespace Foo {
public ref class ThirdPartyInterfacingBar : Bar {
public:
ThirdPartyInterfacingBar();
virtual property array<Quux^, 1>^ Quuxes;
};
}
但现在我对如何在随附的 .cpp
文件中实现它感到困惑。
当做类似的事情时(#include
剥离)
namespace Foo{
array<Quux^, 1>^ ThirdPartyInterfacingBar::Quuxes { /*...*/ }
}
我得到:C2048: function 'cli::array<Type,dimension> ^Foo::ThirdPartyInterfacingBar::Quuxes::get(void)' already has a body
我唯一能想到的是这样的:
namespace Foo {
public ref class ThirdPartyInterfacingBar : Bar {
private:
array<Quux^, 1>^ delegateGetQuuxes();
public:
ThirdPartyInterfacingBar();
virtual property array<Quux^, 1>^ Quuxes {
array<Quux^, 1>^ get() {
return delegateGetQuuxes();
}
}
};
}
并在随附的 cpp 文件中实现 delegateGetQuuxes
。但我认为这很丑陋,因为我不想在 header 中有任何逻辑。有没有更好的方法?
看来您只是忘记了 get()。正确的语法是:
.h file:
public ref class ThirdPartyInterfacingBar : Bar {
public:
property array<Quux^>^ Quuxes {
virtual array<Quux^>^ get();
}
};
.cpp file:
array<Quux^>^ ThirdPartyInterfacingBar::Quuxes::get() {
return delegateGetQuuxes();
}
我有一个基于 VB.net 的界面,如下所示:
Namespace Foo
Public Interface Bar
ReadOnly Property Quuxes as Quux()
End Interface
End Namespace
我现在想在 VC++/CLI 中实现它(因为我需要从非托管 third-party DLL 接口函数),但是我无法弄清楚如何实现的正确语法它。
这是我目前拥有的 header 文件的相关部分:
namespace Foo {
public ref class ThirdPartyInterfacingBar : Bar {
public:
ThirdPartyInterfacingBar();
virtual property array<Quux^, 1>^ Quuxes;
};
}
但现在我对如何在随附的 .cpp
文件中实现它感到困惑。
当做类似的事情时(#include
剥离)
namespace Foo{
array<Quux^, 1>^ ThirdPartyInterfacingBar::Quuxes { /*...*/ }
}
我得到:C2048: function 'cli::array<Type,dimension> ^Foo::ThirdPartyInterfacingBar::Quuxes::get(void)' already has a body
我唯一能想到的是这样的:
namespace Foo {
public ref class ThirdPartyInterfacingBar : Bar {
private:
array<Quux^, 1>^ delegateGetQuuxes();
public:
ThirdPartyInterfacingBar();
virtual property array<Quux^, 1>^ Quuxes {
array<Quux^, 1>^ get() {
return delegateGetQuuxes();
}
}
};
}
并在随附的 cpp 文件中实现 delegateGetQuuxes
。但我认为这很丑陋,因为我不想在 header 中有任何逻辑。有没有更好的方法?
看来您只是忘记了 get()。正确的语法是:
.h file:
public ref class ThirdPartyInterfacingBar : Bar {
public:
property array<Quux^>^ Quuxes {
virtual array<Quux^>^ get();
}
};
.cpp file:
array<Quux^>^ ThirdPartyInterfacingBar::Quuxes::get() {
return delegateGetQuuxes();
}