2015-06-16 26 views
0

我有一个这样的VB.net基于接口:如何在VC++/CLI中实现VB.net中定义的接口?

Namespace Foo 

    Public Interface Bar 

     ReadOnly Property Quuxes as Quux() 
    End Interface 
End Namespace 

我现在想在VC来实现这个++/CLI(因为我需要从非托管的第三方DLL接口函数),但是我想不通出正确的语法如何实现它。

这里是我的头文件中的相关部分我到目前为止:

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(); 
      } 
     } 
    }; 
} 

和实施delegateGetQuuxes在伴随的cpp文件。但我认为这很丑陋,因为我不想在标题中有任何逻辑。有没有更好的办法?

回答

1

看起来你忘了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(); 
}