当我试图插入这个'食物'对象到我的模板类链接列表'测试'。我得到这个错误:模板类链接列表插入错误
request for member ‘addNode’ in ‘test’, which is of non-class type ‘Catalog<FoodSource>()
这是我的编码,我做错了什么?
##main:##
int main(void)
{
Catalog<FoodSource> test();
FoodSource food();
test.addNode(const &food);
return(0);
}
##function definition in .h:##
template<class T>
class Catalog
{
public:
void addNode(const T& value);
};
##function implementation in .cpp:##
template <class T>
void Catalog<T>::addNode(const T& value)
{
Node *temp;
if(head == NULL)
head = new Node (value, NULL);
else
{
temp=head;
while(temp->next !=NULL)
temp=temp->next;
temp->next = new Node (value, NULL);
}
}
aka [最令人头疼的解析](http://en.wikipedia.org/wiki/Most_vexing_parse)。 – 2011-05-03 07:06:38
感谢您的链接。有效的STL正是我了解这个可怕的陷阱的地方......我决定永远不会浪费时间编写C++解析器。 – 6502 2011-05-03 08:49:46