【发布时间】:2009-11-07 19:02:25
【问题描述】:
我有一个简单的容器:
template <class nodeType> list {
public:
struct node {
nodeType info;
node* next;
};
//...
};
现在,有一个名为_search 的函数搜索列表并返回对匹配节点的引用。现在,当我提到函数的返回类型时,我认为它应该是list<nodeType>::node*。这是正确的吗?当我定义内联函数时,它完美地工作:
template <class nodeType> list {
public:
struct node {
nodeType info;
node* next;
};
node* _search {
node* temp;
// search for the node
return temp;
}
};
但是,如果我在类之外定义函数,
template <class nodeType> list<nodeType>::node* list<nodeType>::_search() {
//function
}
它不起作用。编译器给出一个错误说Expected constructor before list<nodeType>::_search 或其他东西。错误与此类似。我目前没有可以测试的机器。
真诚感谢任何帮助。
【问题讨论】:
标签: c++ templates data-structures containers