Question

Ok I am writing a code to modify .ppm image files. A pic gets read in and stored in a PPM class object. Each Pixel is stored in a RGB struct. Eventually it will convert all the colors in the original image to ones from a small color pallet. It does this by using a distance function I created that calculates how close one color is to another. It loops through the color pallet and inserts them into a map with the key being the distance from the current pixel in the image. Somehow ive messed up the syntax with inserting it into the map. Any help?

Below is part of the giant error that is spit out

support.cpp: In member function 'void PPM::process1()': support.cpp:144:78: error: no matching function for call to 'std::pair::pair(float, RGB&)'

Here is the part of the code the error comes from. Its in how I use the insert function. I cant get the RGB class to match what the compiler wants and am unsure what I am doing wrong.

Edit: Update I am aware that as the code is currently it won't work. I havent flushed it out. I like to try and get syntax errors out of the way early.

void PPM::process1()
{
  // for each pixel {
  //   find  closest qcolor
  //   set pixel color to closest qcolor
  // }
    map<float, RGB()> distanceTest;
    RGB RGBtemp;
    map<float,RGB()>::iterator it;
    for(int i = 0; i < img.size(); ++i){
        for(int j = 0; j < qcolors.size(); ++j){
            RGBtemp = qcolors[j];
            distanceTest.insert(pair<float,RGB()>(img[i].distance(qcolors[j]), RGBtemp));
        }
        it = distanceTest.begin();
        distanceTest.clear();
    }
}

Below is all of the Header code that is related.

typedef unsigned char uchar;
typedef enum { run_process1, run_process2 } pmode_t;

struct RGB {
  // constructor/destructor
    RGB(uchar R=0, uchar G=0, uchar B=0);
      // operator< overload
    float distance(RGB);
    uchar R, G, B;
};

class PPM {
  public:
    PPM();
    ~PPM();

    void read(const string &);
    void write(const string &);
    void write(const string &, const string &);
    void process(pmode_t, const string &);

  private:
    string magicid;
    int nrows, ncols;
    int maxvalue;
    vector<RGB> img;
    vector<RGB> qcolors;

    void read_qcolors(const string &);
    void process1();
    void process2();
};
Was it helpful?

Solution

Your syntax for the template parameter list is incorrect. Omit the parentheses following the name of your type and you should be fine:

 map<float, RGB> distanceTest; //no ()

This is referred to as "the most vexing parse."

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top