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

  • SEARCH
  • Home
  • 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 7524163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:00:48+00:00 2026-05-30T03:00:48+00:00

I have just started programming in C++ and I was playing around with templates.

  • 0

I have just started programming in C++ and I was playing around with templates.

The following code fails at run time and I have no clue why. (Please note that it is just a sample code and not used in production)

 bool maxCompare(string* s1,string* s2){
    cout<<*s1<<endl;
    cout<<*s2<<endl;    
    return true; //If I comment this line and instead use the line below, it works fine.
    //return *s1 < *s2;
}

int main()
{
    string* s1=new string("Hello");
    string* s2=new string("Hi");
    string *s3= max(s1,s2,maxCompare);
}
  • 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-05-30T03:00:50+00:00Added an answer on May 30, 2026 at 3:00 am

    Your operator is invalid. In stl’s implementation of max there is an assertion for the comparison function that it can never happen that both a < b and b < a are true. If you come to think a bit this should never really happen. Your second function does not have this problem so it works. Also check that if you return false it will work.

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

Sidebar

Related Questions

Have just started playing with ASP.NET MVC and have stumbled over the following situation.
i have just started android programming, wrote a quick code, and havn't managed to
I have just started programming and have made a few small applications in C
I have just started the Assembly language programming and in the first lecture our
I have just started reading Modern C++ Design Generic programming and Design Patterns Applied
I have just started with Gui Programming in netbeans (Using the template Java Desktop
I have just started to learn the very basics of Java programming. Using a
I'm a real noob who just started learning 3d programming and i have a
I have just recently started out programming for Android, and have decided that I
I have just started learning Objective-C, I am reading Programming in Objective-C 3rd Edition

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.