[英]Forward declaration of nested template classes
I have a class similar to this: 我有一个类似这样的类:
template< typename T, typename Allocator >
class MemMngList : protected LockFreeMemMng<Node, Link>
{
public:
typedef T Type;
typedef Allocator AllocatorType;
struct Node : public LockFreeNode
{
public:
struct Link : protected LockFreeLink< Node >
{
....
The problem is I get an error in template argument for LockFreeMemMng('Node' : undeclared identifier...). 问题是我在LockFreeMemMng的模板参数中遇到错误('Node':未声明的标识符......)。
How can I use forward declaration of Node
and Link
in above of MemMngList implementaion? 如何在MemMngList实现的上面使用Node
和Link
前向声明?
template< typename T, typename Allocator >
class MemMngList;
//Forward Declaration of Node and Link
You can't forward declare something inside a class declaration. 你不能在类声明中转发声明的东西。 You need to move it somewhere outside the class and use friend if you want to access private members: 如果要访问私有成员,您需要将其移到课堂外的某个地方并使用朋友:
template <typename T, typename Allocator>
struct NodeType : public LockFreeNode< NodeType<T,Allocator> >
{
...
template <typename,typename>
friend class MemMngList;
};
template <typename T, typename Allocator>
struct LinkType : public LockFreeLink< NodeType <T,Allocator> >
{
...
template <typename,typename>
friend class MemMngList;
};
template< typename T, typename Allocator >
class MemMngList : protected LockFreeMemMng< NodeType <T,Allocator> , LinkType <T,Allocator> >
{
typedef NodeType <T,Allocator> Node;
typedef LinkType <T,Allocator> Link;
...
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.