2009-08-24 15 views
4

我有一個C++/CLI的類,我想給一個屬性。我想在頭文件中聲明該屬性,然後在.cpp文件中實現該屬性。如何在C++/CLI中轉發聲明屬性?

這裏的標題:

public ref class Dude 
{ 
    static property Dude^ instance 
    { 
     Dude^ get();  
    } 
} 

如果我宣佈了頭文件,不要把任何東西在CPP,我得到以下錯誤:

1>Dude.obj : error LNK2020: unresolved token (06000001) Test.Dude::get_instance 

由此我得出的結論是我應該實現財產

static Lock myInstanceLock; 

    Dude^ Dude::get_instance() 
    { 

     if(myInstance == nullptr) 
     { 
      myInstanceLock.lock(); 
      if(myInstance == nullptr) 
      { 
       myInstance = gcnew Dude(); 
      } 
      myInstanceLock.unlock();    
     } 
     return myInstance; 
    } 

但是,當我編譯此代碼時,我得到了一堆錯誤。第一個錯誤(其他人是第一個錯誤)的結果是:

1>.\Dude.cpp(13) : error C2039: 'get_instance' : is not a member of 'Test::Dude' 

任何人都可以在這個問題上找到一些啓示嗎?

回答

10

更改實施:

Dude^ Dude::instance::get() 
+0

感謝您的幫助! – 2009-08-24 15:13:37