【发布时间】:2013-12-17 17:25:54
【问题描述】:
我正在尝试创建一个应该定义图形搜索算法行为的类。
该类接收一个通用容器作为模板参数并根据该容器进行操作
template <typename N, typename E, class Container>
class Frontier {
private:
Container frontier;
public:
bool isEmpty() { return this.frontier.empty(); }
typename Graph<N, E>::const_iterator pop() { return this.frontier.pop(); }
bool push(typename Graph<N, E>::const_iterator it) { return this.frontier.push(it); }
};
但是当我尝试编译时,我得到了
request for member ‘frontier’ in ‘this’, which is of non-class type
我知道这是可以做到的,因为 stl 容器就是这样实现的
template<class T, Class C = deque<T> > class std::stack;
我注意到 Class 中的大写 C,所以我尝试在实现中使用 Class,但我从编译器得到“未定义类”。我该如何解决这个问题?
【问题讨论】:
标签: c++ templates containers