Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9174271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:43:29+00:00 2026-06-17T16:43:29+00:00

I am working on a school assignment, and I get this strange error (I

  • 0

I am working on a school assignment, and I get this strange error (I am quite new to C++).

I should find the first value between 1500 and 1900. When I build it the first time, everything is ok, but when I build it the next time, I get this error:

error LNK2005: "bool __cdecl greaterThan1500SmallerThan1900(int)" (?greaterThan1500SmallerThan1900@@YA_NH@Z) already defined in Lab5.obj

If I then change the code slightly (change the type in the predicate function to double) it builds again one time.

template<typename T>
T MyStlClass<T>::myFindIf(list<T> &theList) {

    list<T>::iterator it = find_if(theList.begin(), theList.end(), greaterThan1500SmallerThan1900);
    return *it;
}

bool greaterThan1500SmallerThan1900(int value){
    return (value >= 1500 && value <= 1900);
}

I have read on this site that it is because that I include the “.cpp” file, but on the other hand, I have also read, that I need to include the “.cpp” file, when I am using templates.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:43:29+00:00Added an answer on June 17, 2026 at 4:43 pm

    I have also read, that I need to include the “.cpp” file, when I am using templates.

    Throw away/downvote/identify for us the resource that told you to do that.

    There is a good reason that it did so, but the recommendation was wrong and it has led you directly to this issue.

    Never #include a .cpp.

    The file you put template definitions in should be called something like .ipp rather than .cpp, so that then your IDE does not confuse it with a “regular” source file and build it with the rest of your project. Such a file is then, like a .h, only #included.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a school assignment and I've been completely stumped with this step.
I've been working on this school assignment. The assignment told us to make an
I'm working on my first GWT-based Java project for a school assignment. It's a
I'm working on this for a school assignment http://cit.dixie.edu/cs/1410/asst_bulkrename.html . I just finished coding
I have this school assignment that I've been working on and am totally stumped
I am working on a school assignment that requires me to be able to
Im working on a school project and it's my first time on android development.
I am working on an mySQL assignment for school and I am stuck on
Im working on a school assignment, and im supposed to make a array of
This is a school assignment and I have most of it under control, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.