當我試圖插入這個'食物'對象到我的模板類鏈接列表'測試'。我得到這個錯誤:模板類鏈接列表插入錯誤
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