views:

168

answers:

1

I have a class in C++/CLI that I'd like to give a property. I want to declare the property in a header file and then implement that property in a .cpp file.

Here's the header:

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

If I declare the header file and don't put anything in the cpp, i get the following error:

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

From this I concluded that I should implement the property as

  static Lock myInstanceLock;

   Dude^ Dude::get_instance()
   {

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

However, when I compile this code, I get a bunch of errors. The first error (The others are a result of the first one) is:

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

Can anyone shed some light on this issue?

+7  A: 

Change the implementation to:

Dude^ Dude::instance::get()
Mehrdad Afshari
Thanks for your help!
Mark P Neyer