Undefined reference, even though all object files are included

I have a template (non-member) function that is declared inside a namespace in an hpp file and defined in a cpp file. It is compiled, and the corresponding o file is sent to the linker OK. My main.cpp includes the relevant hpp file. But I still get an "undefined reference" error to the function when I try to call it from main(). I'm stumped. What could be wrong?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Templates need to be declared and defined in the hpp file. The compiler replaces the template arguments to generate actual code it will compile then. So the cpp won't be looked at, when you use the template inside another cpp file.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
>>What could be wrong?

The problem is that - even though the C++ standard allows separating template declarations and implementations - there's no compiler out there that supports that. So, the easiest workaround is to

#include "template.cpp"
As of now, the most widely approach being declaring and defining the templates functions/classes in the header file itself since most compilers do not support separating template declarations from implementation.

The following link provides an explanatio for the same


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.