我在声明内部模板类时遇到问题。
我Class A
在a.h
这里创建了一个我的代码看起来像
class A
{
public:
private:
// How declare LockFreeQueue here
};
template <typename T>
struct LockFreeQueue
{
LockFreeQueue();
void push(const T& t);
bool pop(T& t);
private:
typedef std::list<T> TList;
TList list;
typename TList::iterator iHead, iTail;
};
/**
* Constructor
* Initializes required variables
* */
template <typename T>
LockFreeQueue<T>::LockFreeQueue()
{
list.push_back(T());
iHead = list.begin();
iTail = list.end();
}
/**
* pushes data in the list
* @param datatype that needs to be pushed
* */
template <typename T>
void LockFreeQueue<T>::push(const T& t)
{
list.push_back(t);
iTail = list.end();
list.erase(list.begin(), iHead);
}
/**
* Pops Queue
* @param t stores popped data at t's address
* @return true if data available, false otherwise
* */
template <typename T>
bool LockFreeQueue<T>::pop(T& t)
{
typename TList::iterator iNext = iHead;
++iNext;
if (iNext != iTail)
{
iHead = iNext;
t = *iHead;
return true;
}
return false;
}
任何帮助将不胜感激,
谢谢 & BR Yuvi