-1

I just started learning the opencv library for c++. In my previous c++ experience (which isn't much) I've never encountered the following syntax

IplImage* dopPyrDown (
            IplImage * in,
            int filter = IPL_GAUSSIAN_5x5
    ) {
        assert(in->width%2 == 0 && i->height%2 == 0);
        IplImage* out = cvCreteImage(
         cvSize(in->width/2, in->height/2),
         in->depth,
         in->nChannels
        );
        cvPyrDown(in, out);
        return(out);
    };

More specifically, I mean the "IplImage* dopPurDown (*argument*){*code*};" Could someone explain what It means?

sinθ
  • 11,093
  • 25
  • 85
  • 121
  • It's a function. That should be enough to get you going. – chris Jun 18 '12 at 02:53
  • You mean a function definition? – Mysticial Jun 18 '12 at 02:53
  • 3
    Maybe you are confused because there is an extraneous semicolon at the end?? – Jesse Good Jun 18 '12 at 02:53
  • I was confused because of the line breaks in the arguments. I didn't recognize it as a function. Sort of seems obvious now. – sinθ Jun 18 '12 at 02:59
  • @MikeG: Unlike some other languages like Python, line breaks are generally not significant. The braces and semicolons, on the other hand, are very significant and can change program semantics. You may want to pick up a C++ book to really learn the syntax rules. – In silico Jun 18 '12 at 03:02
  • @Insilico It was more of a recognition thing. I've never programed in a language like python that cares about white-space and stuff. The book wasn't clear on what it was (since it should be obvious) so it looked to me like some mutation of a class definition and a function call. – sinθ Jun 18 '12 at 03:05
  • @Mike G: Well, now you know. :-) It's also a good demonstration of how indentation/spacing can really affect code readability, even if it doesn't change how the program works. – In silico Jun 18 '12 at 03:08

1 Answers1

7

More specifically, I mean the "IplImage* dopPurDown (argument){code};" Could someone explain what It means?

It's declaring a function called dopPurDown which returns a pointer to a IplImage and accepts some arguments (in this case, two arguments called in and filter). The code in between the brackets define the function.

Before you go on, please pick up a good introductory C++ book as functions are fundamental to pretty much every high-level programming language in existence. Quite frankly, if you can't recognize a function definition in C++ you need to step back and learn C++ properly first before trying to tackle on OpenCV, which is an entirely different beast.

Community
  • 1
  • 1
In silico
  • 51,091
  • 10
  • 150
  • 143
  • Oh... thanks. Sorry. I'm so used to seeing it as int foo(int a int b) with not line breaks that I didn't recognize it with line breaks. – sinθ Jun 18 '12 at 02:57
  • @Mike G: That's okay, but it's even more reason to pick up a C++ book so you can really learn the syntax rules of the language. Generally speaking, line breaks are not significant. Semicolons, on the other hand, are significant in many situations. Again, I recommend you pick up a good C++ book (use the link I provided in the answer as a guide) so you can learn the syntax. – In silico Jun 18 '12 at 02:58