0

I try to return multiple values by reference.

enum Color {ORANGE, YELLOW, GREEN, BLUE, VIOLET, RED};
int main(int argc, const char * argv[])
{
    CvScalar hsv_min, hsv_max;
    choose_color(RED, hsv_min, hsv_max);

    return 0;
}

void choose_color(Color farbe, CvScalar &min, CvScalar &max) {
    switch (farbe) {
        case ORANGE:
            min = cvScalar(0,50,50);
            max = cvScalar(0,255,255);
            break;
        default:
            throw "choose color: invalid case!";
            break;
    }
 };

Why do I get "use of undeclared identifier" for the choose_color call?

bro
  • 771
  • 3
  • 14

2 Answers2

2

Because your main function needs to know that your choose_color exists.

You need to do a forward declaration (place the prototype of the function before the main function):

enum Color {ORANGE, YELLOW, GREEN, BLUE, VIOLET, RED};

// Forward declaration
void choose_color(Color farbe, CvScalar &min, CvScalar &max); // function prototype

int main(int argc, const char * argv[])
{
    CvScalar hsv_min, hsv_max;
    choose_color(RED, hsv_min, hsv_max);

    return 0;
}

void choose_color(Color farbe, CvScalar &min, CvScalar &max) {
// ...
};

Here is great explanation about forward declaration.

The other solution is to define the main after your choose_color function.

Community
  • 1
  • 1
Pierre Fourgeaud
  • 14,290
  • 1
  • 38
  • 62
0

place main() after choose_color() or, better, declare the function above main():

void choose_color(Color farbe, CvScalar &min, CvScalar &max);
int main(int argc, const char * argv[])
{
...
}
CapelliC
  • 59,646
  • 5
  • 47
  • 90