Search code examples
c++function-declaration

How do you declare a function with definition func(cv::Mat &img) in C++


How do you declare a function defined as such:

void func(cv::Mat &img)
{
    ...
}

More details:

I defined the function "func" in my main.cpp file below the "main" function. The compiler complained that it didn't know what the function "func" was, so I tried to put the prototype above the "main" function.

I tried

void func(cv::Mat);

but that didn't work.


Solution

  • Declare?

    Just

    void func(cv::Mat &img);
    

    and that's it. Or even just

    void func(cv::Mat &);
    

    since parameter names in non-defining declarations serve no purpose (aside from making the code more readable).

    However, for most entities in C++ (and C) a definition is just a specific kind of declaration (i.e. the term "definition" can be thought of as just a shorthand for "defining declaration"). By defining this function you also declared it (for the code that follows the definition).