Re: error LNK2022: metadata operation failed - using Templates?
As stated above, the LinkedList files (unmodified) work if I put the
declaration of the linked list and calls to insertAtHead in my Form1.h
file. Why should it make a difference if they are in my City class
instead?
Any suggestions would be greatly appreciated!
Hi cyndi,
You cannot put template implementations in a seperated files without
including the seperated file to the header.
The result if you're doing something like this, you have expirienced ;)
So do it in this way:
// LinkedList.h
template <typename Item>
ref class LinkedList
{
private:
ref class node
{
public:
node() { data = Item(); link=nullptr; }
node(const Item% init_data, node ^init_link)
{ data = init_data; link = init_link; }
Item data;
node ^link;
};
public:
typedef node ^NodePtr;
LinkedList(void)
{
head = nullptr;
}
void insertAtHead(const Item % entry)
{
head = gcnew node(entry, head);
}
private:
NodePtr head;
};
And drop the LinkedList.cpp
The rest can be keeped.
And you'll see it will work ;)
Regards,
Vinzenz