undefined reference to..passing a stl::queue to a function

Hello,

I'm trying to pass a queue to a function. My queue uses a type I've created called "node" and is defined as:

queue<node> bredthFringe;

the function I'm attempting to call is:

currentNode.addChildrenToFringe(bredthFringe);

It's definition in node.ccp is:

1
2
3
template<typename T> void node::addChildrenToFringe(T &fringeQueue){
//doing stuff with fringeQueue here
}


and in node.h is:

template< typename T > void node::addChildrenToFringe(T &fringeQueue);

The error I get is:

1
2
In function bredthFirstSearch:
undefined reference to `void node::addChildrenToFringe<std::queue<node, std::deque<node, std::allocator<node> > > >(std::queue<node, std::deque<node, std::allocator<node> > >&)' 


I don't understand this error enough to track down what I'm doing wrong. Does anyone have any ideas?

Thank you for your time,
Elliott
Template functions must be implemented in the header file.
Really, that's it?!

I guess in the examples I saw they just had a forward declaration and then the implementation below in one .cpp file - so I assumed the dec. would go in the header and the implementation in the .cpp. Guess I was wrong!

Thank you!
I guess in the examples I saw they just had a forward declaration and then the implementation below in one .cpp file - so I assumed the dec. would go in the header and the implementation in the .cpp. Guess I was wrong!


That's exactly what you do except for templates.

For non-template functions, you had the right idea. Templates are just weird.
Topic archived. No new replies allowed.