我有一个单州图书馆,来自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