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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:48:51+00:00 2026-05-28T07:48:51+00:00

I have defined the classes ‘Outcome’ and ‘Bin’. I am trying to pass an

  • 0

I have defined the classes ‘Outcome’ and ‘Bin’.
I am trying to pass an array of type Outcome to a Bin Constructor, in order to add each element of that array to a set of ‘Outcome’s that is a member property of the Bin Class.

//Bin.h
class Bin {
private:
    std::set<Outcome> outcomeset;
public:
    Bin();
    Bin(Outcome Outcs[], int numberofelements);
    Bin(std::set<Outcome> Outcs);
    void add(Outcome Outc);
    std::string read();

};

//In Bin.cpp

Bin::Bin(Outcome outcs[], int numberofelements) {
    int i;
    for (i=0;i<(numberofelements-1);i++) {
        outcomeset.insert(outcs[i]); //When this LIne is commented out, no compile errors!
    }
}

This results in a whole mess of errors in VS2010 that link back to library files. I have been unable to find anything online or in my “The Big C++” textbook. Is this a completely wrong implementation of this sort of functionality? Or am I missing something rather basic?

For the curious I am implementing this as part of the ‘Roulette’ Problem from this free textbook http://www.itmaybeahack.com/homepage/books/oodesign.html

Thanks for your help!

EDIT: I have added the (rather lengthy) error text to a pastebin, here: http://pastebin.com/cqe0KF3K

EDIT2: I have implemented the == != and < operators for the outcome class, and the same line still does not compile. Here are the implementations

//Outcome.cpp
bool Outcome::operator==(Outcome compoutc) {
    if (mEqual(compoutc) == true) {
    return true;
}
else {
    return false;
}
}

bool Outcome::operator!=(Outcome compoutc) {
if (mEqual(compoutc) == false) {
    return true;
}
else {
    return false;
}
}

bool Outcome::operator<(Outcome compoutc) {
if (odds < compoutc.odds) {
    return true;
}
else {
    return false;
}
}

EDIT3: Implemented the comparison operator with the de-referenced parameter and const tags and now it compiles!

  • 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-28T07:48:51+00:00Added an answer on May 28, 2026 at 7:48 am

    You need to define an operator< for the class being inserted into the set.

    Also note that instead of an explicit loop, you’re probably better off using a pair of “iterators” (pointers, in this case) and actually initializing the set:

    #include <set>
    #include <string>
    
    class Outcome { 
        int val;
    public:
        bool operator<(Outcome const &other) const { 
            return val < other.val;
        }
        Outcome(int v = 0) : val(v) {}
    };
    
    class Bin {
    private:
        std::set<Outcome> outcomeset;
    public:
        Bin();
    
        // Actually initialize the set:
        Bin(Outcome Outcs[], int n) : outcomeset(Outcs, Outcs+n) {}
        Bin(std::set<Outcome> Outcs);
        void add(Outcome Outc);
        std::string read();
    
    };
    
    int main() { 
        // Create an array of Outcomes
        Outcome outcomes[] = {Outcome(0), Outcome(1) };
    
        // use them to initialize the bin:
        Bin b((outcomes),2);
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

if I have two classes, and have defined an explicit type conversion between them,
I have defined a constant array in one of my classes as: static const
I have two classes defined in different h files and each class has some
I have a jsp page that is trying to reference some user defined classes.
I have defined an Event class: Event and all the following classes inherit from
I have always wondered why you cannot use locally defined classes as predicates to
I have the following classes defined to do validation: public class DefValidator : IValidate<IDef>
I have seen some C++ classes with a destructor defined as follows: class someClass
My doc strings have references to other python classes that I've defined. Every time
I have defined classes: public class Parent : IParent { public string ParentText {

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.