CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2009
    Posts
    28

    Question 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.

  2. #2
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    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.
    «_Superman
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

  3. #3
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Two the same class/function templates in two different files

    Quote Originally Posted by Quentin026 View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured