-
August 19th, 2009, 03:30 AM
#1
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.
-
August 19th, 2009, 05:02 AM
#2
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.
-
August 19th, 2009, 10:01 AM
#3
Re: Two the same class/function templates in two different files
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.
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?
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|