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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:59:09+00:00 2026-05-31T18:59:09+00:00

I am using an std::set to hold members of type Board , and I

  • 0

I am using an std::set to hold members of type Board, and I want to iterate over the set to do comparisons that will not work with the find method as different criteria will be used for sorting verses locating.

1>c:\...\project.cpp(1140): error C2440: 'initializing' : cannot convert from 'std::_Tree_const_iterator<_Mytree>' to 'std::_Tree_const_iterator<_Mytree>'
1>          with
1>          [
1>              _Mytree=std::_Tree_val<std::_Tset_traits<Board,std::greater<Board>,std::allocator<Board>,false>>
1>          ]
1>          and
1>          [
1>              _Mytree=std::_Tree_val<std::_Tset_traits<Board,std::less<Board>,std::allocator<Board>,false>>
1>          ]
1>          No constructor could take the source type, or constructor overload resolution was ambiguous

the thing is the iterator should not be const. the method is not const, the set is created local to the method, and I do not preface the iterator as const.

Thing::Thing thisFunction(int action){
    // snip 
    set<Board, less<Board>> openSet;
    // snip 
    for(set<Board>::iterator ii = openSet.begin();  // line 1140
        ii != openSet.end(); ii++){
            // snip 
    }

this does not make direct sense as the iterator is not declared const so it should not be trying to even consider const.

separately why is the compiler talking about a std::_tree when I am using a std::set

  • 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-31T18:59:10+00:00Added an answer on May 31, 2026 at 6:59 pm

    The problem is relatively simple, you cannot assign a

    std::set<Board, std::greater<Board>>::iterator 
    

    to a

    std::set<Board>::iterator 
    

    because that is actually a

    std::set<Board, std::less<Board>>::iterator 
    

    The standard does not guarantee that these are the same type, and it is not guaranteed that there will be a conversion between them. In practice, these are always different types, and there is no conversion. Thus your error.

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

Sidebar

Related Questions

I want to reverse the contents of a std::set (Not just iterating theough it
#include <list> #include <set> #include <iterator> #include <algorithm> using namespace std; class MyContainer {
What is the preferred method of using std::rel_ops to add the full set of
In my main.cpp: using namespace std; #include <cstdlib> #include <iostream> #include <set> #include <string>
I'm adding two different elements to both std::list and std::set and I want the
When is using a std::set more efficient (w.r.t. time) than using a std::vector along
I am trying to combine using a std::set and a class, like this: #include
i have written a sample program.below: #include<iostream> #include<string> #include<set> using namespace std; int main()
I have a std::set<std::string> and I want to know the exact position of the
I have a std::set which is of type point struct point { int x;

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.