Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ cli 如何在C++/CLI?_C++ Cli_Properties_Forward Declaration - Fatal编程技术网

C++ cli 如何在C++/CLI?

C++ cli 如何在C++/CLI?,c++-cli,properties,forward-declaration,C++ Cli,Properties,Forward Declaration,我有一个C++/CLI中的类,我想给它一个属性。我想在头文件中声明该属性,然后在.cpp文件中实现该属性 以下是标题: public ref class Dude { static property Dude^ instance { Dude^ get(); } } 如果我声明了头文件,但没有在cpp中放入任何内容,则会出现以下错误: 1>Dude.obj : error LNK2020: unresolved token (0600000

我有一个C++/CLI中的类,我想给它一个属性。我想在头文件中声明该属性,然后在.cpp文件中实现该属性

以下是标题:

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;
   }
然而,当我编译这段代码时,我得到了一堆错误。第一个错误(其他错误是第一个错误的结果)是:


有人能解释一下这个问题吗?

将实现更改为:

Dude^ Dude::instance::get()
Dude^ Dude::instance::get()