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 9151489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:48:55+00:00 2026-06-17T11:48:55+00:00

I have a problem with this code (cubeBoxData is a set of cubeBox): cubeBox

  • 0

I have a problem with this code (cubeBoxData is a set of cubeBox):

cubeBox temp(bx,by,bz);
cubeBoxData.insert(temp);
set<cubeBox>::iterator i = cubeBoxData.find(temp);
const_cast<cubeBox&>(*i).addCube(x,y,z);

The problem is that cubeBoxData.find(temp); doesn’t find temp, then the program fails trying to call addCube(), and I don`t know why, because this code works fine (just change the third line):

cubeBox temp(bx,by,bz);
cubeBoxData.insert(temp);
set<cubeBox>::iterator i = find(cubeBoxData.begin(),cubeBoxData.end(),temp);
const_cast<cubeBox&>(*i).addCube(x,y,z);

The operator < for cubeBox is:

bool operator<(const cubeBox& c) const {
    return x<c.x ? true : y<c.y ? true : z<c.z ? true : false;
}

And addCube doesn’t change x, y or z.

I think my operator< is wrong and I’m missing something silly, but i can´t figure what is it.

  • 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-17T11:48:56+00:00Added an answer on June 17, 2026 at 11:48 am

    The operator< that you have defined does not establish a strict weak ordering. For example, according to your comparator, it is both the case that {1,0,1} < {0,1,0} and that {0,1,0} < {1,0,1}. As a result, all of the operations on the set have undefined behaviour.

    You should rewrite your comparison operation so that it does establish a strict weak ordering. The easiest(?) way to do this is to use std::tuple:

    bool operator<(const cubeBox& c) const {
        return std::tie(x,y,z) < std::tie(c.x,c.y,c.z);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with this is code: Set oXmlHTTP = CreateObject(Microsoft.XMLHTTP) oXmlHTTP.Open POST,
I have a problem with this code: setInterval(function() { var timed = $(#chMsgCont).find(.chatMsg:last-child); var
Hi i have problem in this code it says Object reference not set to
I have a problem with this code: <?php echo <meta http-equiv='refresh' content='3;search_enroll.php?&id='.$id />; ?>
I have weird problem with this code $('img').hover(function(){ var $cap = $(this).parent().find('.cap'); window.setTimeout(function(){$cap.stop(true,false).animate({bottom:164},500)},500); },function(){
I have a problem with this code. You can find all classes here .
I have some problem with this code. Notice the comments. Why that? struct node
I have a problem with this code. This is a tutorial code that show
The problem is that this code display nothing. I have problem with my loads
I have this problem, my code doesn't work when i try to find eyes

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.