Please consider the code below. This is a smaller version of what I'm trying to accomplish.

Point instances will get random values to be printed in a 2D grid. In order not to have duplicates, I'm inserting them in positions.

ret pair is used by me in order to know whether a new element was inserted (ret.second == true) or not (ret.second == false).

The problem is that I get the message:

a.cpp:59:77: error: invalid operands of types 'bool' and '<unresolved overloaded function type>' to binary 'operator<<'

when try to compare ret.second with true or false.

What am I doing wrong?

#include <iostream>
using std::cout; using std::cerr; using std::endl; using std::cin;
#include <string>
using std::string;
#include <vector>
using std::vector;
#include <map>
using std::map;
#include <set>
using std::set;
#include <utility>
using std::pair; using std::make_pair;
#include <cmath>
#include <cstdlib>


class Point
{

public:
    unsigned int x_pos;
    unsigned int y_pos;
};

int main ()
{
    std::vector<Point *> stream;
    std::set<std::pair<unsigned int, unsigned int> > positions;
    pair<set<pair<unsigned int, unsigned int> >::iterator, bool> ret;

    Point * p = new Point;
    p->x_pos = 3;
    p->y_pos = 4;
    stream.push_back(p);

    p->x_pos = 1;
    p->y_pos = 1;
    stream.push_back(p);

    unsigned int x_rand;
    unsigned int y_rand;

    unsigned int i (0);    // Assign a position for every point in the stream not yet assigned to the 2D world.               
    for (vector<Point *>::iterator it = stream.begin(); it != stream.end(); ++it) {

        cout << "iteration: " << i << endl;
        ret.second = false;

        while ( ret.second == false ) {
            x_rand = rand() % 2;
            y_rand = 0; // this would be another nr.                                                                          

            pair <unsigned int, unsigned int> p (x_rand, y_rand);
            cout << "    try to insert pair x,y = " << x_rand << "," << y_rand << endl;
            ret = positions.insert (p);

            if (ret.second == false) { cout << "element already present: " << endl; }
            else { cout << "   just inserted new element. " << ret.second==true << endl; }   // ERROR IN THIS LINE.
        }
        ++i;
    }
}

Try this cout << " just inserted new element. " << (ret.second==true) << endl; or better yet just cout << " just inserted new element. " << ret.second << endl;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.