Runtime error with Activator::CreateInstance

Hi all,

I have taken over a piece of code developed by a contractor. This code appears to run fine on him machine from Visual Studio, however when I try the same code, from the same version of VS, on my machine I get an error when it makes a call to Activator::CreateInstance. Code below. Does anyone know why this might be happening? Is he using the function correctly? Is there not a standard singleton class? surprised he has created his own!

Thanks in advance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
generic< class T > public ref class Singleton abstract
{
public:
  /*
   * Create an instance of the singleton class
   * @return A handle to the singleton class
   */
  static T  				Instance()
  {
    // Check if the object has already been created
    if( m_Instance == nullptr )
    {
      // ####### Runtime error here #######
      m_Instance = safe_cast< T >( System::Activator::CreateInstance( T::typeid ) );
    }
    return( m_Instance );
  }

protected:
  /* Default Constructor */
  Singleton< T >()
  {
  }

  /* Copy Constructor */
  Singleton< T >( const T )
  {
  }

  /* Assignment Operator */
  const T operator = ( const T   )
  {
    return( safe_cast< const T >( this ) );
  }

private:
  // Handle to the single instance of the class created in the system
  static T  			m_Instance;
};

Topic archived. No new replies allowed.