报错:does not name a type

-LanPei- 2014-07-07 04:57:18
代码中两个类要交叉引用:

#ifndef ITEMSET_H
#define ITEMSET_H

#include <string>
#include <vector>
#include "ItemSorter.h"

using namespace std;

namespace A
{
namespace B
{
class ItemSet
{
public:
typedef vector<string>::size_type size_type;
typedef vector<string>::iterator iterator;


private:
vector<string> items;
ItemSorter<ItemSet> sorter;
};
}
}

#endif



#ifndef ITEMSORTER_H
#define ITEMSORTER_H

#include "ItemSet.h"

namespace A
{
namespace B
{
template<typename T>
class ItemSorter
{
public:
typedef typename T::iterator targetIter;
public:
ItemSorter();
public:
void sort(targetIter begin, targetIter end)
{

}
};
}
}

#endif


编译时,报错:

In file included from ItemSorter.h:4:0:
ItemSet.h:23:4: error: ‘ItemSorter’ does not name a type
ItemSorter<ItemSet> sorter;


我是想采用模板的方式进行交叉引用。
...全文
1398 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
-LanPei- 2014-07-08
  • 打赏
  • 举报
回复
对于类与类互相引用的情况,大家是怎么做的呢?
-LanPei- 2014-07-07
  • 打赏
  • 举报
回复
引用 1 楼 lx458004975 的回复:
前置声明。。
那我的代码的前置声明应该怎么写呢?
偏爱风流 2014-07-07
  • 打赏
  • 举报
回复
前置声明。。

64,649

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧