Function template has already been defined

This is a discussion on Function template has already been defined within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by phantomotap Your original source shadows the template parameter names(A nested template and the containing template both use ...

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,033
    Quote Originally Posted by phantomotap View Post
    Your original source shadows the template parameter names(A nested template and the containing template both use the entity name `T'.)
    Dang, obvious mistake. I must think harder about this in the future!
    I hate it when the compiler lets stuff like that slip through... I DON'T want to compile with two compilers!

    According to my first attempt at compiling the source you've committed the common sin of not telling the compiler where certain names come from. (You need to add the occasional `parent::' or `this->' I imagine.)
    Does this usually not come when using members from a base in a derived class?
    So as as I know (which may not always be much), it should be OK if it references local members in the current class.

    As for the incorrectly cast pointers... I introduced those problems because I don't have Boost or the 64 bit stuff.
    I see. Those casts should be correct, though, since Windows demands them.

    Edit: I just realized I called you "him" again...

    Soma
    Doesn't really matter ^^"
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,415
    "Does this usually not come when using members from a base in a derived class?"

    *shrug*

    From what I've seen, it shows up the most when inheriting from template classes--even fully instantiated ones--because many compiler don't propagate names correctly if templates are in any way involved. (See the Sun "CC" compiler for an example.)

    "So as as I know [...] references local members in the current class."

    Unless the name is otherwise ambiguous.

    "Those casts should be correct, though, since Windows demands them."

    O_o

    Whatever you say...

    "Doesn't really matter ^^""

    o_O

    Whatever you say...

    Soma

  3. #18
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    You mean, the code I posted to show Elysia the kinds of compiler errors I wanted him to examine/eliminate had errors? (Edit: To clarify, I had no idea why the original source Elysia posted was getting those errors. I assumed that the inline definition inside a class trumped the issue CornedBee explained. To that end, I was trying to broil the problem down to something I could solve.)
    I was talking about your definition of test2 (which I was assuming was your "correct" code):
    Code:
    struct test2
    {
       template<typename TN, typename UN>
       friend bool operator == <> (const test2<TN> & lhs, const test2<UN>& rhs);
       private: int i;
    };

  4. #19
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Quote Originally Posted by Elysia View Post
    Tricky. Very tricky.
    I get your point, but everytime I would instantiate Foo with the same types, I would get an exact same function again, just like in the above.
    A template is instantiated only once for a set of types per compilation unit.

    Plus they're marked as inline which should make the compiler ignore multiple definitions,
    Code:
    inline void f() {}
    inline void f() {}
    Will this compile? No. The compiler doesn't ignore multiple definitions. The compiler never ignores multiple definitions.
    Inline and templates make the linker ignore multiple definitions, not the compiler.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,033
    I see. It's all clear now.
    The dark corners of C++ can scare anyone.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking problems in Visual Studio
    By h3ro in forum C++ Programming
    Replies: 5
    Last Post: 03-04-2008, 02:39 PM
  2. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  3. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 09:56 AM
  4. errors initializing D3D
    By Vacation Guy in forum C++ Programming
    Replies: 3
    Last Post: 08-07-2005, 01:20 PM
  5. DLL compiling question
    By Noose in forum Windows Programming
    Replies: 2
    Last Post: 12-16-2004, 07:16 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21