-2

我正在尝试创建如下列表。但有错误。

#ifndef CLASS1_H
#define CLASS1_H
#include <list>
class class2
{

};
class class3
{

};
class class1
{
public:
    typedef std::list<class2, class3*> m_list;
    m_list mylist;
};
#endif

错误是:

In file included from /usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/list:63:0,
                 from class1.h:3:
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_list.h: In instantiation of ‘std::_List_base<class2, class3*>’:
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_list.h:418:5:   instantiated from ‘std::list<class2, class3*>’
class1.h:16:9:   instantiated from here
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_list.h:294:9: error: ‘class3*’ is not a class, struct, or union type
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_list.h:296:60: error: ‘class3*’ is not a class, struct, or union type
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_list.h: In instantiation of ‘std::list<class2, class3*>’:
class1.h:16:9:   instantiated from here
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_list.h:420:58: error: ‘class3*’ is not a class, struct, or union type
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_list.h:449:20: error: no members matching ‘std::list<class2, class3*>::_Base::_M_get_Tp_allocator’ in ‘class std::list<class2, class3*>::_Base’
/usr/lib/gcc/i686-pc-cygwin/4.5.3/include/c++/bits/stl_list.h:450:20: error: no members matching ‘std::list<class2, class3*>::_Base::_M_get_Node_allocator’ in ‘class std::list<class2, class3*>::_Base’

请任何人知道这件事,请帮助我。

4

2 回答 2

2
template<
    class T,
    class Allocator = std::allocator<T>
> class list;

忽略分配器,std::list只取一种,而不是两种。

allocator 必须是满足 STL 分配器要求的类,不能是指针。

于 2013-05-02T03:59:03.550 回答
1

您可能需要地图,而不是列表。如果您确实想要包含这两个类的列表,则可以使用 std::pair 使这两个类显示为单个元素:

 typedef std::list<std::pair<class2, class3*> > m_list;
于 2013-05-02T04:21:26.603 回答