2012-01-19 72 views
1

下面是我宣佈接口:如何在託管C++中實現接口?

[ServiceContract] 
public interface class IShedluer 
{ 
    [OperationContract] 
    array<Object^>^ GetResult(UInt64 taskId); 
} 

下面是試圖實現它的類:

ref class MyShedluer:IShedluer 
{ 
    Shedluer ^shedluer;//this is NOT MyShedluer 
public: 
    MyShedluer(void); 

    array<Object^>^ GetResult(UInt64 taskId) 
    { 
     return shedluer->GetResult(taskId); 
    } 
} 

當我嘗試編譯此,我越來越

Error 15 error C3766: 'MyShedluer' must provide an implementation for 
the interface method 'cli::array<Type> ^IShedluer::GetResult(unsigned __int64)' 
d:\users\menkaur\documents\visual studio 2010\projects\MyProject\ 
\kernel\MyShedluer.h 78 1 MyProject.Kernel 

爲什麼我得到這個?

回答

5

,實現接口的正確語法是添加virtual

ref class MyShedluer:IShedluer 
{ 
public: 
    virtual array<Object^>^ GetResult(UInt64 taskId); 
} 

此外,編譯器會告訴你這一點,看看你的警告,以及:

warning C4488: 'MyShedluer::GetResult' : requires 'virtual' keyword 
to implement the interface method 'IShedluer::GetResult'