Two the same class/function templates in two different files
Hi there,
I've got two exactly the same class templates in two different files but linker (from MS Visual 2008 Express and DevC++ 4.9.9.2) doesn't show any errors. The question is: why ? It just deletes one of them (and two of them if I've got three templates etc.). A strict linkage doesn't applicable class/function templates ?
Thank you,
Quentin.
Re: Two the same class/function templates in two different files
They are probably inside different namespaces.
Code:
namespace one
{
template<typename T>
class A
{
};
}
namespace two
{
template<typename T>
class A
{
};
}
This will compile.
Re: Two the same class/function templates in two different files
Quote:
Originally Posted by
Quentin026
I've got two exactly the same class templates in two different files but linker (from MS Visual 2008 Express and DevC++ 4.9.9.2) doesn't show any errors. The question is: why ?
Because the template class is only defined once you use it with a specific template argument. The same goes for template functions.
Quote:
It just deletes one of them (and two of them if I've got three templates etc.). A strict linkage doesn't applicable class/function templates ?
It's probably not deleted, just ignored. Can you explain how you include the header files with the template class definitions in various cpp files?