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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:12:54+00:00 2026-06-04T06:12:54+00:00

i created a stuct which contains one character and one string struct M2E {

  • 0

i created a stuct which contains one character and one string

 struct M2E
 { char english;
 string morse;}

by using code given by, i created a binary tree of M2E which is bintree
but i want to sort these M2Es in string morse order(“*” less than “-“)
so i did a operater overloading in struct M2E

 bool operator == (M2E& other) const
{
    return morse.compare(other.morse);
}

but i keep giving the following error message when im compling

no match for "operator ==" in ((binNode<M2E>*)this)->binNode<M2E>::nodeData == dataItem
note:candidates are :bool M2E::operator==(M2E&) const

the code i am using for binary tree which is bintree.h is:

  template <typename dataType> class bintree
{  
  private:
  binNode<dataType> *root;
  int numItems;

  void insert(const dataType& newData) 
  {
     // insert the newData into the tree

     if (root == NULL) 
     {
        root = new binNode<dataType>(newData);
     } 
     else 
     {
        root->insert(root, newData);
     }
     numItems++;
  }

the code im using for binary node which is binnode.h is:

  template <typename dataType> class binNode 
 {
 private:
  // private data ====================================
  dataType nodeData;
  binNode<dataType> *left, *right;

        void insert(binNode<dataType>* &root, const dataType& dataItem) 
  {
     if (nodeData == dataItem) 
     {
        throw std::invalid_argument("dataItem already in tree");
     }

     if (dataItem < nodeData) 
     {
        if (left == NULL) 
        {
           left = new binNode(dataItem);
        } 
        else 
        {
           left->insert(left, dataItem);
        }
     } 
     else 
     {
        if (right == NULL) 
        {
           right = new binNode(dataItem);
        } 
        else 
        {
           right->insert(right, dataItem);
        }
     }
     rebalance(root);
  }

thx for helping

  • 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-04T06:12:55+00:00Added an answer on June 4, 2026 at 6:12 am

    The problem is that you are taking a const datatype dataItem in insert(), but the operator== takes a non-const M2E parameter.

    You need to specify the operator== parameter type to be const:

    bool operator == (const M2E& other) const {
      //...
    }
    

    Remember that const is a contract: the function promises not to change the value of its parameter. So insert() makes this promise, but operator== does not, so insert() cannot make that operator call it as-is. By adding the const to operator==‘s parameter type, you make operator== make the same promise, so insert() can call it

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

Sidebar

Related Questions

I have a struct which contains a member called char *text. After I've created
Suppose I compile a source file file which contains this piece of code, struct
I have a file which is created by a program. It contains html code
I have created a master page (Site.master) which contains the code to display a
I've been using the following code to create various struct, but only give people
In C++, I have a class which contains an anonymous bitfield struct. I want
I've got a struct (say Foo ) which contains simply strings and a double
Class SampleFiveA extends JPanel. This contains textfields, one below the other, each of which
I want to create a struct which is like a CGPoint, but with 3
I have a group of 13 properties in a class. I created a struct

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.