English 中文(简体)
单吨温度舱在从气lin到窗户时的协同效应
原标题:Syntax error in Singleton Template class when porting from linux to windows

我有一个单州图书馆,来自Im试图进入Windows的灯塔项目。 当我试图汇编时,它有误,有误。

syntax误差:识别符号“rpSingleton”

错误来自法典以下部分:

template <typename T> inline T& 
   Q::Singleton<T>::Instance()
   {
   Singleton<T>*& rp_singleton(rpSingleton()); //ERRORS HERE
   if (0 == rp_singleton)
      {
      rp_singleton = new Singleton<T>;
      }
   return rp_singleton->mInstance;
   }

Below is the whole file for reference. Any idea what s wrong?

#ifndef Q_SINGLETON_H
#define Q_SINGLETON_H

// SYSTEM INCLUDES

#include <boost/noncopyable.hpp>

// PROJECT INCLUDES

// LOCAL INCLUDES

#include "NonDerivable.h"

// NAMESPACES

namespace Q
{
   template <typename T> class Singleton;
}

// FORWARD REFERENCES

namespace Q
{
template <typename T> void InstanceCleanup();
}


template <typename T> class Q::Singleton 
   : private boost::noncopyable
   , private virtual Qf::NonDerivable
   {
   // FRIENDS

   // Allow only T specialization of Instance be a friend
   friend T& Instance<T>();

   // Allow only the T specialization of Instance be a friend
   friend void InstanceCleanup<T>();

   public:
   protected:
   private:
   /// The single object
   T mInstance;

   /// Wrapper method of a static pointer to support instance and clean up
   ///
   static Singleton<T>*& rpSingleton();

   /// Constructor is private, must use Instance Method to use the object
   ///
   Singleton();

   /// Get the Instance of the Singleton
   /// 
eturn The Instance
   static T& Instance();

   /// A way to free this singleton s resources before program termination
   ///
   static void CleanUp();

   };

// INLINE METHODS

template <typename T> inline T& 
   Q::Singleton<T>::Instance()
   {
   Singleton<T>*& rp_singleton(rpSingleton());
   if (0 == rp_singleton)
      {
      rp_singleton = new Singleton<T>;
      }
   return rp_singleton->mInstance;
   }

template <typename T> inline void 
   Q::Singleton<T>::CleanUp()
   {
   delete rpSingleton();
   rpSingleton() = 0;
   }

template <typename T> inline Q::Singleton<T>*& 
   Q::Singleton<T>::rpSingleton()
   {
   static Singleton<T>* sp_singleton(0);
   return sp_singleton;
   }

template <typename T> inline Q::Singleton<T>::Singleton()
   {
   }

template <typename T> inline T& Q::Instance()
   {
   return Singleton<T>::Instance();
   }

template <typename T> inline void Q::InstanceCleanup()
   {
   Singleton<T>::CleanUp();
   }

// NON-INLINE METHODS (TEMPLATE CLASSES ONLY!!!!)

#endif // SINGLETON_H
问题回答

为此:

Singleton<T>*& rp_singleton = rpSingleton();

Fixes it. But does that make any sense?





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签