我在内部模板类的声明中面临问题。
我在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;
}
任何帮助都将受到高度赞赏,
谢谢&amp; BR Yuvi
答案 0 :(得分:3)
把它移到里面:
class A
{
public:
private:
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;
};
};
在定义时添加A
的范围,如下所示:
template <typename T>
A::LockFreeQueue<T>::LockFreeQueue()