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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:44:09+00:00 2026-06-06T01:44:09+00:00

I have a class class Item { int _one; int _two; int _three; //

  • 0

I have a class

class Item {
    int _one;
    int _two;
    int _three;
    // other stuff
};

class ItemList : public std::vector<Item> {
    // deriving from std vector because the ctor needs to
    // perform some work in discriminating what gets added
    // to the list
};

I’ve read many of the arguments against deriving from std::vector<> and I think I’ll be ok because this class isn’t to be derived from. I’m exposing this in python, using the boost vector indexing suite, to act as a python list. Because I needed the constructor to do some work in eliminating certain elements from the list during construction, I decided to go this route instead of doing what I’ve done elsewhere in the project:

class AnotherItem {
    // class definition
};
typedef std::vector<AnotherItem> AnotherItemList

And then expose the list with boost vector indexing suite using the typedef. All seems well except that I have this error: Error 2 error C2678: binary ‘==’ : no operator found which takes a left-hand operand of type ‘Item’ (or there is no acceptable conversion)

The error isn’t coming from the boost libraries but something in the std algorithm code. I’ve tried to added my own class overloaded == operator, but this hasn’t fixed the problem. It looks like this:

class Item {
    // earlier stuff
    bool operator==(Item& rhs) {
        return (_one == rhs._one && _two == rhs._two && _three == rhs._three);
    }
    bool operator!=(Item& rhs) {
        return !(*this == rhs);
    }
};

This hasn’t fixed the issue. What am I missing? This link here shows that the == operator for vector is NOT a member function. I tried overloading at the “global” level (I.e. not within a namespace), but this didn’t help either. So, what am I missing?

Thanks,
Andy

  • 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-06T01:44:10+00:00Added an answer on June 6, 2026 at 1:44 am

    The proper overload for == is

    class Item
    {
        ...
        bool operator==(const Item& rhs) const
        { .... }
    
        bool operator!=(const Item& rhs) const
        { return !(*this==rhs); }
    };
    

    Also, be shure that, because std::vector doesn’t have virtual members, your derived ItelmList cannot be used polymorphically against std::vector itself, in particular don’t call delete against an std::vector*.

    I have to say this because otherwise me and you will be doomed by tha C++ communinty although in 30+ year of experience in programming I never never never saw a std::vector* or an std::string*. (And hence I really don’t know all the “scare” about deriving std classes is about: simply know what you are doing and let other people know)

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

Sidebar

Related Questions

I have the following class: class Item { public string[] field1; public int field2;
I have the following: class Item { public object ItemId {get;set;} } class StringItem
I have some custom type: [RdfSerializable] public class Item { [RdfProperty(true)] public string Name
Suppose I have the following two data structures: std::vector<int> all_items; std::set<int> bad_items; The all_items
I have my view models : public class POReceiptViewModel { public virtual int PONumber
Let's say we have: @Entity public class Order { @Id private int id; @OneToMany(mappedBy=order)
I have the jquery: $(.item) which gives me all elements of class item. I
class Item(models.Model): ... class ItemSet(models.Model): items = models.ManyToManyField(Item, related_name=itemsets) I have a list of
I have a Model with a Foreign Key of Parent class Item(models.Model): parent =
I have a datastore model representing items in an ecommerce site: class Item(db.Model): CSIN

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.