proper declaration for template link problem

Discussion in 'C++' started by Jeff Kish, Oct 3, 2006.

  1. Jeff Kish

    Jeff Kish Guest

    Hi.

    I'm stuck using a very old c++ compiler, and I'm trying to figure out how to
    add a declaration so that an algorithm can be used. This is really a compiler
    specific problem, however I was hoping someone could suggest the proper
    declaration to put in place to solve it.

    If someone can suggest a solution I'd really appreciate it.

    Here is the scenario:

    I have an object, and I use a vector and vector Iterator with it.

    the old build system I'm using (borland 5.02) is set up
    with the projects I'm stuck with to generate external references to all
    template instances.

    This requires that I put all template instances into a standalone cpp file
    that is built differently so that they are all resolved to that cpp.

    this works fine except when I add a call to:
    sort(myvector.begin(),myvector.end()) or
    find(myvector.begin(),myvector.end(),anObject)

    I get unresolved linker errors.

    Now I figure I need to add the sort and find functions to the .cpp file
    that resolves all the other template components like vector.size() etc.

    I can't figure out what to add though, to the file.

    I tried adding things like:
    std::find(MAnnotation*,MAnnotation*, const MAnnotation&);

    because of the error description which said:
    Error: Error: Unresolved external 'std::sort(MAnnotation*,MAnnotation*)'
    referenced from module STLSortVectortester.cpp

    but it did not resolve the link problem.

    I appreciate any assistance.

    Thanks
    Jeff Kish
     
    Jeff Kish, Oct 3, 2006
    #1
    1. Advertising

  2. Jeff Kish

    Jeff Kish Guest

    On Tue, 03 Oct 2006 13:39:41 -0400, Jeff Kish <> wrote:

    >Hi.
    >
    >I'm stuck using a very old c++ compiler, and I'm trying to figure out how to
    >add a declaration so that an algorithm can be used. This is really a compiler
    >specific problem, however I was hoping someone could suggest the proper
    >declaration to put in place to solve it.
    >
    >If someone can suggest a solution I'd really appreciate it.
    >
    >Here is the scenario:
    >
    >I have an object, and I use a vector and vector Iterator with it.
    >
    >the old build system I'm using (borland 5.02) is set up
    >with the projects I'm stuck with to generate external references to all
    >template instances.
    >
    >This requires that I put all template instances into a standalone cpp file
    >that is built differently so that they are all resolved to that cpp.
    >
    >this works fine except when I add a call to:
    >sort(myvector.begin(),myvector.end()) or
    >find(myvector.begin(),myvector.end(),anObject)
    >
    >I get unresolved linker errors.
    >
    >Now I figure I need to add the sort and find functions to the .cpp file
    >that resolves all the other template components like vector.size() etc.
    >
    >I can't figure out what to add though, to the file.
    >
    >I tried adding things like:
    >std::find(MAnnotation*,MAnnotation*, const MAnnotation&);
    >
    >because of the error description which said:
    >Error: Error: Unresolved external 'std::sort(MAnnotation*,MAnnotation*)'
    >referenced from module STLSortVectortester.cpp
    >
    >but it did not resolve the link problem.
    >
    >I appreciate any assistance.
    >
    >Thanks
    >Jeff Kish

    I guess I'm tired.. this worked.
    MAnnotation* std::find(MAnnotation*,MAnnotation*, const MAnnotation&);
    I forgot that the return types are implictly int if I don't specify them which
    was wrong.
    Jeff Kish
     
    Jeff Kish, Oct 3, 2006
    #2
    1. Advertising

  3. Jeff Kish

    Marcus Kwok Guest

    Jeff Kish <> wrote:
    > On Tue, 03 Oct 2006 13:39:41 -0400, Jeff Kish <> wrote:
    >>I'm stuck using a very old c++ compiler, and I'm trying to figure out how to
    >>add a declaration so that an algorithm can be used. This is really a compiler
    >>specific problem, however I was hoping someone could suggest the proper
    >>declaration to put in place to solve it.
    >>
    >>I tried adding things like:
    >>std::find(MAnnotation*,MAnnotation*, const MAnnotation&);
    >>
    >>because of the error description which said:
    >>Error: Error: Unresolved external 'std::sort(MAnnotation*,MAnnotation*)'
    >>referenced from module STLSortVectortester.cpp
    >>
    >>but it did not resolve the link problem.

    >
    > I guess I'm tired.. this worked.
    > MAnnotation* std::find(MAnnotation*,MAnnotation*, const MAnnotation&);
    > I forgot that the return types are implictly int if I don't specify them which
    > was wrong.


    Maybe this is true since you must use an old compiler, but IIRC in
    current C++ implicit return type is no longer supported... unfortunately
    VS .NET 2003 SP1 has no qualms about compiling this code with all
    warnings enabled; in fact, I couldn't even get it to warn me about
    implicit int (if it did, it was buried underneath a bunch of warnings
    for standard headers); of course, Comeau online gives the error:
    explicit type is missing ("int" assumed).


    #include <iostream>

    f()
    {
    return 42;
    }

    int main()
    {
    f();
    }

    --
    Marcus Kwok
    Replace 'invalid' with 'net' to reply
     
    Marcus Kwok, Oct 3, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Spencer

    Re: Link Link Link DANGER WILL ROBINSON!!!

    Kevin Spencer, May 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    941
    Kevin Spencer
    May 17, 2005
  2. blueblueblue2005
    Replies:
    6
    Views:
    1,029
    blueblueblue2005
    Jul 19, 2005
  3. Alex Buell
    Replies:
    2
    Views:
    685
    Alex Buell
    Feb 21, 2006
  4. Joseph Turian
    Replies:
    2
    Views:
    894
    Joseph Turian
    Mar 22, 2007
  5. Proper way Variable declaration

    , Mar 5, 2008, in forum: C Programming
    Replies:
    11
    Views:
    638
    CBFalconer
    Mar 7, 2008
Loading...

Share This Page